Last Updated: March 2, 2026
A machine coding interview is a timed exercise, typically 60 to 90 minutes, where you receive a problem statement and must produce working code in an IDE of your choice. The interviewer wants to see actual classes, actual methods, and an actual demo that runs.
This format is heavily used by companies in India and increasingly by global tech firms. Flipkart, PhonePe, Atlassian, Uber, Swiggy, Cred, and Groww all include machine coding rounds in their interview pipelines. Some companies give you the problem in advance (30 minutes to 1 hour of prep time), while others hand it to you on the spot.
The problem statement is usually 1 to 2 pages long and describes a real-world system: a parking lot, a meeting room scheduler, a food delivery app, a stock exchange. You will see a list of features the system should support, sometimes with explicit constraints ("support multiple floors," "handle concurrent bookings") and sometimes deliberately vague to test whether you ask clarifying questions.
This is fundamentally different from an OOD interview. In OOD, you spend most of your time on designing classes and discussion. In machine coding, your design phase should be 15-20% of the total time at most. The rest is implementation, testing, and bug fixing. You are evaluated on what you deliver, not what you describe.
You are expected to produce a runnable codebase with clean class design, working logic, and a demo (usually a Main class) that exercises the core workflows.
This chapter covers a 5-phase framework for machine coding interviews, using Stack Overflow as the running example.
Here are the 5 phases:
Read the problem statement carefully. Then read it again. Underline or note every action the system must support. Separate what is explicitly required from what is implied or ambiguous.
If you are allowed to ask the interviewer questions, this is the time.
Write down your requirements in a MUST HAVE / NICE TO HAVE format. This keeps you focused on what matters and gives you a clear list to work through.
You are not required to sketch out a detailed UML diagrams. You need just enough structure to start coding without second-guessing every class and method.
There is a simple trick that works surprisingly well: read the problem statement and highlight the nouns, verbs, and adjectives.
For the Stack Overflow example, the problem statement says: "Users can ask questions with tags, post answers, add comments, and upvote or downvote content." That single sentence gives you six classes and five methods.
One more class that does not appear in the problem statement but you always need: a manager or service class that ties everything together. This is the entry point for all operations. Call it StackOverflow, StackOverflowService, or StackOverflowManager. It holds collections of users and questions, and every public operation goes through it.
Your choice of data structures during the design phase directly affects how much code you write later. Get this right and implementation flows naturally.
Map<Integer, User> when you need to look up entities by ID. This is almost always the case for your manager class. If users is a List<User>, finding a user by ID requires a loop every time. With a Map, it is O(1).Map<Integer, Vote> (keyed by voter's user ID) for deduplication. When a user votes, you check votes.containsKey(userId). This is cleaner and faster than iterating a list to check if they already voted.List<Answer> when order matters and you do not need fast lookup by ID. Answers on a question are naturally ordered by time, and you rarely need to find a specific answer by ID.Rule of thumb: If you will ever ask "does this collection contain X?" or "give me the item with ID Y," use a Map. If you just iterate through items or care about order, use a List.
VoteType.UPVOTE, VoteType.DOWNVOTE. This prevents bugs from typos like "upvte" and makes your code self-documenting.isClosed. But avoid boolean parameters in methods because vote(user, question, true) is unreadable. What does true mean? Use an enum instead: vote(user, question, VoteType.UPVOTE).status = "open" is a bug waiting to happen. Someone will type "Open" or "OPEN" and your equality check will fail silently.Write this on paper or in a comment block:
Classes: User, Question, Answer, Comment, Tag, Vote, StackOverflow (manager)
Relationships:
Key methods on StackOverflow:
createUser, askQuestion, postAnswer, addComment, vote, searchQuestionsDo not do this in a machine coding interview:
You will discover design issues while coding. That is fine. Refactor as you go.
Before writing any business logic, set up your project skeleton. This takes 3-5 minutes but saves much more than that.
First, it compiles immediately. You have a project that builds and runs from minute 10. Every change you make from this point is incremental. You never face the dreaded "I have 500 lines of code and none of it compiles" situation at minute 50.
Second, it gives you navigation. When you are deep in the implementation phase and need to add a method to Question, you know exactly where to find it. Under time pressure, hunting through a single 400-line file for the right class wastes minutes you cannot afford.
Third, it provides psychological momentum. You have created files, written constructors, and your project runs. You are no longer staring at a blank screen. The hardest part of any timed exercise is getting started, and a skeleton removes that friction.
Stick to whatever convention your language uses. Do not invent your own style.
camelCase for methods and variables, PascalCase for classes. getUserById, not get_user_by_id.snake_case for methods and variables, PascalCase for classes. get_user_by_id, not getUserById.For the model vs service distinction: model classes hold data and behavior related to a single entity (Question knows how to add an answer to itself). The service class coordinates operations across multiple entities (StackOverflow knows how to connect a user's answer to a question). If you are unsure where a method goes, ask: "Does this operation need to know about more than one entity?" If yes, it belongs in the service class.
Start by creating all your classes with just the fields and constructor. Do not write any logic yet. This gives you a complete skeleton to fill in.
Now create the two content classes. Both Question and Answer need comments and votes, so they share similar fields:
All your model classes now exist. The project should compile with no errors even though nothing happens yet.
Spend 40-50 minutes here. The goal: get all core operations working end-to-end so you can run test cases and see correct output.
Build your code bottom-up: models first, then the service class, then main.
Why this order? Because each layer depends only on the layer below it. When you write StackOverflow.askQuestion(), the User, Question, and Tag classes already exist and compile. You never write a method that calls something you have not built yet. This means every method you write can be tested the moment you finish it.
The opposite approach, starting with main and working down, leads to a cascade of compilation errors. You write stackoverflow.askQuestion(...) but askQuestion does not exist yet. Then you create the method but Question does not exist. You end up with 10 files open, all broken, and no way to test anything. Bottom-up avoids this entirely.
VoteType)Tag, Comment, Vote)User, Answer, Question)StackOverflow)Look at your MUST HAVE list from Phase 1. Work through it in priority order. If you reach minute 50 and you have three features left, make a judgment call: which ones are essential and which can be left as TODOs?
Leave a clear comment for anything you skip:
This tells the interviewer two things: you identified the requirement, and you know how you would implement it. That is worth partial credit. An empty gap with no comment looks like you forgot the feature entirely.
One more thing: never skip validation in favor of new features. A system that handles 4 features with proper error handling scores higher than a system that handles 6 features but crashes on invalid input.
Build it method by method, testing as you go.
Now write a main entry point that exercises all the functionality. This doubles as your test harness and the first thing anyone reviewing your code will read.
When you run this, you should see:
You now have a fully working system. Compile it, run it, verify the output. If you are past the 60-minute mark and everything above works, you are in good shape.
Core functionality works. Spend your remaining 20-25 minutes hardening the solution.
Before diving into your specific problem, run through these categories mentally. They apply to almost every machine coding problem.
Go through each operation and ask "what could go wrong?":
Question.addAnswer().Do not write all your code and test at the end. Instead, test after each major component:
If you find a bug, fix it immediately. Do not keep going and hope to fix it later. A small bug left unfixed often cascades into bigger issues.
In the last 5 minutes:
userId and user_id)