Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started

Explaining Code Execution

MediumCoding00:00
Practice interviewer
In session
5 left
00:00

Your question is Explaining Code Execution. Take a moment with it on the right.

Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).

You need to log in / sign up to chat or submit.

Problem

You're a backend engineer at Interactive Process Technology, working on a batch job that applies discounts to a set of pending orders and prints a run summary to the deploy log. Here is the method your interviewer hands you.

public class DiscountCalculator {
    static int callCount = 0;

    static int applyDiscount(int price) {
        callCount++;
        return price - (price / 10);
    }

    public static void main(String[] args) {
        int[] prices = {50, 99, 100, 250};
        int total = 0;
        int i = 0;

        while (i < prices.length) {
            int discounted = applyDiscount(prices[i]);
            total += discounted;
            i++;
        }

        System.out.println("Processed: " + callCount + " orders");
        System.out.println("Total after discount: $" + total);
        System.out.println("Average order: $" + total / prices.length);
        System.out.println("Message: " + 1 + 2 + " items, " + (1 + 2) + " unique SKUs");
    }
}

Explain exactly what gets printed to the console when this runs, line by line, and explain your reasoning for each line rather than just stating the final numbers.