Machine Coding Round
The machine coding round is a 60-90 minute live coding exercise where you design and implement a small system from scratch. Unlike DSA rounds that test algorithmic thinking, this round tests whether you can write production-quality object-oriented code under time pressure.
Why this matters: Most product companies (Flipkart, Uber, Swiggy, PhonePe, Atlassian) use this round as a primary filter. Candidates who clear DSA rounds often fail here because writing clean, extensible code is a fundamentally different skill than solving LeetCode problems.
Prerequisites
- SOLID Principles β the grading rubric directly evaluates these
- Class Design Approach β your first 5 minutes
How It Differs from DSA Rounds
| Dimension | DSA Round | Machine Coding Round |
|---|---|---|
| Goal | Optimal algorithm | Clean, working design |
| Time | 45 min per problem | 60-90 min, one problem |
| Evaluation | Correctness + complexity | Design + extensibility + correctness |
| Code style | Doesnβt matter much | Matters enormously |
| Testing | Run against hidden cases | You write your own driver |
| Patterns | Array tricks, graph algos | OOP patterns, SOLID |
| What fails you | TLE or wrong answer | God class, rigid design, no separation |
What Youβre Building
Typical problems ask you to build a simplified version of a real system:
- Parking Lot management
- Splitwise expense sharing
- Elevator system
- Vending machine
- Snake and Ladder game
- Task scheduler
- Rate limiter
The problem statement is intentionally under-specified. Youβre expected to ask clarifying questions and make reasonable assumptions.
The Grading Rubric
Interviewers typically score on these axes (though they wonβt tell you this):
flowchart LR
A["Working Code<br/>40%"]:::client
B["Design Quality<br/>30%"]:::service
C["Extensibility<br/>20%"]:::data
D["Code Hygiene<br/>10%"]:::client
A --> B
B --> C
C --> D
classDef client fill:#4c3a5e,stroke:#818cf8,color:#e2e8f0
classDef service fill:#1a3a2a,stroke:#4ade80,color:#e2e8f0
classDef data fill:#3b3520,stroke:#fbbf24,color:#e2e8f0
Working Code (40%) β Does the core flow actually run? Can you demo it? Partial implementations that compile and handle the happy path score better than ambitious designs that donβt run.
Design Quality (30%) β Are responsibilities cleanly separated? Are you using appropriate patterns? Is there a clear separation between models, services, and orchestration?
Extensibility (20%) β If the interviewer says βnow add X,β how much code do you need to change? A good design means adding a new feature touches 1-2 files, not 10.
Code Hygiene (10%) β Naming conventions, no magic numbers, proper access modifiers, small methods. This is the easiest 10% to earn.
The 90-Minute Breakdown
This is a battle-tested time allocation:
| Phase | Time | What You Do |
|---|---|---|
| Clarify | 0-5 min | Ask questions, write down assumptions |
| Design Sketch | 5-15 min | Identify entities, relationships, key interfaces |
| Core Models | 15-30 min | Write entity classes, enums, value objects |
| Service Layer | 30-55 min | Implement business logic, wire things together |
| Driver/Demo | 55-70 min | Write main method that demonstrates the system |
| Edge Cases | 70-80 min | Handle nulls, invalid input, boundary conditions |
| Polish | 80-90 min | Rename, extract methods, add comments on non-obvious logic |
The cardinal sin: Spending 30 minutes on design without writing any code. Interviewers want to see working software. A mediocre design that runs beats an elegant design that doesnβt compile.
What Gets You Rejected
These are the patterns that consistently fail candidates:
1. The God Class One class with 500 lines that does everything. No separation of concerns.
2. Primitive Obsession
Using String type = "CAR" instead of an enum. Using int[] instead of a proper model.
3. No Interfaces Everything is concrete. When the interviewer asks βwhat if we add a new type,β youβre rewriting half the code.
4. Logic in Main
The main method contains business logic instead of just orchestrating calls to services.
5. Not Running the Code You wrote 400 lines but never compiled or ran it. The demo doesnβt work.
Project Structure That Works
Keep it simple. You donβt need Spring Boot or dependency injection frameworks.
src/
models/ # Entities, enums, value objects
service/ # Business logic (one service per responsibility)
strategy/ # If you use Strategy pattern
exception/ # Custom exceptions (2-3 max)
Main.java # Driver that demos the system
The Extensibility Test
After you finish, the interviewer will often ask: βWhat if we need to support X?β Good answers:
- βIβd add a new implementation of this interfaceβ (new class, no existing code changes)
- βIβd add a new strategy hereβ (plug into existing framework)
- βIβd extend this enum and add a case in the factoryβ
Bad answers:
- βIβd add another if-else block in this methodβ
- βIβd modify the existing class to handle both casesβ
- βIβd copy this class and change the parts that differβ
Common Mistakes in the First 5 Minutes
- Not asking about scale β βHow many concurrent users?β determines whether you need thread safety
- Not asking about persistence β Most machine coding rounds are in-memory only. Donβt waste time on DB schemas
- Not asking about input format β βWill I get API calls, or should I read from stdin?β
- Jumping to code β Without identifying at least your core 3-4 entities, youβll refactor heavily mid-round
Sample Clarifying Questions
Good questions for any machine coding problem:
- βIs this in-memory only, or should I persist to a database?β
- βShould I handle concurrent access, or is single-threaded fine?β
- βWhatβs the input mechanism β method calls, API, or stdin?β
- βWhich features are must-have vs nice-to-have if time runs short?β
- βShould I write unit tests, or is a working demo sufficient?β
Demo Strategy
Your demo should tell a story. Donβt just call random methods β show a realistic flow:
public class Main {
public static void main(String[] args) {
// Setup
ParkingLot lot = new ParkingLot(3, 10); // 3 floors, 10 slots each
// Happy path: park vehicles
Vehicle car1 = new Vehicle("KA-01-1234", VehicleType.CAR);
Ticket t1 = lot.park(car1);
System.out.println("Parked: " + t1); // Floor 1, Slot 1
// Park more to show allocation strategy
Vehicle bike = new Vehicle("KA-02-5678", VehicleType.BIKE);
Ticket t2 = lot.park(bike);
System.out.println("Parked: " + t2); // Floor 1, Slot 2
// Unpark and show billing
Receipt r1 = lot.unpark(t1);
System.out.println("Receipt: " + r1); // Shows duration + cost
// Edge case: lot full
// ... fill remaining slots ...
try {
lot.park(new Vehicle("KA-03-0000", VehicleType.CAR));
} catch (ParkingFullException e) {
System.out.println("Handled: " + e.getMessage());
}
}
}
def main():
# Setup
lot = ParkingLot(floors=3, slots_per_floor=10)
# Happy path
car1 = Vehicle("KA-01-1234", VehicleType.CAR)
t1 = lot.park(car1)
print(f"Parked: {t1}") # Floor 1, Slot 1
# Show allocation
bike = Vehicle("KA-02-5678", VehicleType.BIKE)
t2 = lot.park(bike)
print(f"Parked: {t2}")
# Unpark and billing
r1 = lot.unpark(t1)
print(f"Receipt: {r1}") # Duration + cost
# Edge case: lot full
try:
lot.park(Vehicle("KA-03-0000", VehicleType.CAR))
except ParkingFullError as e:
print(f"Handled: {e}")
if __name__ == "__main__":
main()
#include <iostream>
#include <memory>
int main() {
// Setup
ParkingLot lot(3, 10); // 3 floors, 10 slots each
// Happy path
auto car1 = std::make_shared<Vehicle>("KA-01-1234", VehicleType::CAR);
auto t1 = lot.park(car1);
std::cout << "Parked: " << t1->toString() << std::endl;
// Show allocation
auto bike = std::make_shared<Vehicle>("KA-02-5678", VehicleType::BIKE);
auto t2 = lot.park(bike);
std::cout << "Parked: " << t2->toString() << std::endl;
// Unpark and billing
auto r1 = lot.unpark(t1);
std::cout << "Receipt: " << r1->toString() << std::endl;
// Edge case: lot full
try {
auto overflow = std::make_shared<Vehicle>("KA-03-0000", VehicleType::CAR);
lot.park(overflow);
} catch (const ParkingFullException& e) {
std::cout << "Handled: " << e.what() << std::endl;
}
return 0;
}
When to Use vs When to Avoid (Patterns in Machine Coding)
| Pattern | Use When | Avoid When |
|---|---|---|
| Strategy | βSupport multiple types of Xβ | Only one algorithm, wonβt change |
| Factory | Object creation logic is complex or type-dependent | Simple new suffices |
| Observer | βNotify when X happensβ | No event-driven requirements |
| State | Entity has lifecycle with transitions | States are just a field with no behavior |
| Singleton | Truly global resource (the parking lot itself) | Using it for everything |
| Builder | Object has 5+ optional fields | 2-3 required constructor args |
Interview Questions
-
βWalk me through your design decisions.β β Explain why you separated concerns the way you did. Mention which SOLID principles you applied and where.
-
βHow would you add feature X?β β Show that your design is open for extension. Point to the interface or abstract class that would get a new implementation.
-
βWhat would you do differently with more time?β β Mention thread safety, input validation, logging, or breaking a large service into smaller ones. Shows self-awareness.
-
βWhy didnβt you use pattern Y?β β Have a reason. βI considered it, but for only two variants, the added abstraction wasnβt worth it yetβ is a valid answer.
-
βHow would this scale to handle concurrent users?β β Discuss synchronization points, where locks would go, and which data structures would need to be thread-safe.
See It in Action
| Practice with real problems: Parking Lot | Vending Machine | Elevator | Splitwise | Rate Limiter | Music Player |