Cleartrip SDE-2 Machine Coding Interview Guide

The Cleartrip SDE-2 machine coding round has a well-earned reputation for its brutal 90-minute time limit. You have an hour and a half to build a fully functional, extensible, and thread-safe in-memory application entirely from scratch, which then gets picked apart in a 30-minute code review. Standard algorithmic interviews test your memory of data structures, but this round is entirely different. It forces you to take vague business requirements and turn them into working, object-oriented software while the clock is ticking. Cleartrip operates in the high-stakes travel tech space, meaning their real-world systems handle massive read-heavy traffic and sudden burst writes when users compete for limited inventory. This interview is designed to simulate that exact environment. You will not have access to a database, and you cannot rely on frameworks like Spring Boot or Django to handle concurrency and dependency injection for you. You have to write raw, clean, thread-safe code that compiles and runs flawlessly.
The Cleartrip SDE-2 Interview Process
Before breaking down the machine coding round, it helps to understand where it fits into the broader Cleartrip hiring pipeline. The machine coding round is almost always the first technical hurdle, acting as a massive filter. If you pass this, the subsequent rounds focus heavily on your ability to scale systems and optimize algorithms.
| Round | Duration | Focus Area |
|---|---|---|
| 1. Machine Coding | 90 + 30 mins | LLD, SOLID principles, working code, concurrency |
| 2. Data Structures & Algorithms | 60 mins | Medium/Hard LeetCode, time/space optimization |
| 3. System Design (HLD) | 60 mins | Scalability, microservices, database choices |
| 4. Hiring Manager | 60 mins | Behavioral, past projects, culture fit |
Deconstructing a Typical Cleartrip Prompt
Expect to design something along the lines of a Flight Reservation System, a Hotel Booking Engine, or a Cab Aggregator. Let us use a Flight Reservation System as our running example. The prompt will usually ask you to build a system that supports a specific set of operations through a command-line interface or a hardcoded driver class. You will be asked to implement functionalities like registering users, adding airlines and flights, searching for flights based on source and destination, and booking seats. The requirements will explicitly state that multiple users might try to book the same seat simultaneously, and your system must handle this gracefully. You will be evaluated on your code's modularity, strict separation of concerns, and your ability to manage these concurrent edge cases without relying on external databases.
The 90-Minute Execution Blueprint

Time management is the primary reason strong engineers fail this round. If you spend 40 minutes designing the perfect class hierarchy on paper, you will run out of time to implement the core booking logic. You need a strict execution plan. Stick to this timeline to ensure you have a working product when the timer sounds.
- Minutes 0-15 (Requirements & Design): Read the prompt twice. Identify the core entities, the primary actions, and the exact output format expected. Sketch a quick class diagram on paper. Do not write code yet.
- Minutes 15-30 (Models & Repositories): Create your domain models (e.g., User, Flight, Seat). Set up your in-memory datastore using thread-safe collections. Build simple repository classes to abstract data access.
- Minutes 30-70 (Core Services & Concurrency): This is the meat of the interview. Implement the business logic. Focus heavily on the search functionality and the booking mechanism. Implement your locking strategy here to ensure thread safety.
- Minutes 70-85 (Driver Class & Wiring): Create the main method. Instantiate your repositories and services, wire them together, and write the commands to simulate user actions. Ensure the code compiles and runs.
- Minutes 85-90 (Buffer & Edge Cases): Run your code against the sample inputs provided in the prompt. Fix any null pointer exceptions or logic bugs. If you have time, add a few custom exceptions.
Designing the Domain Models and In-Memory Datastore
First, map out your core entities. For a Flight Reservation System, you need Flight, Seat, User, and Booking classes. Keep your models clean. A Flight should contain attributes like flightNumber, airline, source, destination, departureTime, and a collection of Seat objects. A Seat should have a seatNumber, price, and a status enum (AVAILABLE, BOOKED, HELD). Since you do not have a real database, set up a centralized in-memory datastore. Split your data layer (repositories) away from your business logic (services) right out of the gate so you do not end up with massive, unreadable monolithic classes.
When building your repository layer, use ConcurrentHashMap rather than a standard HashMap. A standard HashMap will throw a ConcurrentModificationException or silently corrupt your data if multiple threads write to it simultaneously. Using ConcurrentHashMap guarantees baseline thread safety for structural modifications. For example, your FlightRepository might contain a ConcurrentHashMap mapping a String flightId to a Flight object. Do not let your services interact with this map directly. Instead, expose methods like saveFlight(Flight flight) and getFlightById(String flightId) to encapsulate the data access logic. This shows the interviewer you understand the Repository pattern.
Mastering Concurrency and Inventory Locks Without a Database
Concurrency is exactly where most candidates crash and burn. Think about what happens when two users try to book the last available seat on a flight at the exact same millisecond. If your code simply checks if the seat is available and then marks it as booked, both threads might read the seat as available simultaneously, resulting in a double-booking. Without database-level row locks (like Postgres's SELECT FOR UPDATE) or distributed locks (like Redis) to save you, application-level locking is your only way out. You have two primary strategies here: pessimistic locking and optimistic locking.
Pessimistic locking involves explicitly blocking other threads from accessing a resource while one thread is modifying it. Do not just put the synchronized keyword on your entire bookSeat method. That creates a global bottleneck, turning your highly concurrent application into a slow, sequential process. Instead, use Java's ReentrantLock or granular synchronized blocks. You should lock at the most granular level possible. For instance, rather than locking the entire Flight object, lock the specific Seat object being booked. This allows User A to book Seat 12A while User B simultaneously books Seat 14C on the same flight without blocking each other.
Optimistic locking is an excellent alternative that often impresses interviewers. Instead of blocking threads, you attach a version attribute (an AtomicInteger) to your Seat entity. When a user wants to book a seat, they read the current version. During the actual booking update, the system checks if the version in memory still matches the version the user read. If it matches, the version increments and the booking succeeds. If it does not match, it means another thread modified the seat in the background, and you throw a SeatAlreadyBookedException. This approach is lock-free, highly performant, and demonstrates a deep understanding of concurrent system design.
Applying SOLID Principles and Design Patterns
Writing working code is only half the battle. The interviewer is actively evaluating your architecture. If your code is a procedural mess of if-else statements inside a single God class, you will fail the round even if the output is perfectly correct. You must demonstrate a practical application of SOLID principles and common design patterns.
- Single Responsibility Principle: Strictly separate your Driver, Services, and Repositories. Your FlightService should handle the business logic of finding flights, while your BookingService handles the transaction of securing a seat. A Service should never instantiate a Repository directly; use constructor injection.
- Strategy Pattern: Drop this in for pricing models or search filters. If the prompt mentions dynamic pricing based on demand versus a flat rate, create a PricingStrategy interface with DefaultPricingStrategy and SurgePricingStrategy implementations. This makes your system instantly extensible.
- Factory Pattern: Rely on this to cleanly instantiate different types of objects. If your system supports different types of users (e.g., RegularUser, PremiumUser) or different notification mechanisms (SMS, Email), a Factory class keeps the instantiation logic out of your core services.
- Exception Handling: Never return nulls or generic boolean flags to indicate failure. Throw custom domain exceptions like SeatUnavailableException, InvalidRouteException, or UserNotFoundException. Catch these in your driver class and print meaningful error messages.
Handling Edge Cases Like a Senior Engineer
To truly stand out, you need to anticipate edge cases that the prompt implies but does not explicitly state. What happens if a user searches for a flight, selects a seat, but their payment fails? If you marked the seat as BOOKED during the selection phase, that inventory is now permanently lost. A senior engineer handles this by introducing a HELD status. When a user selects a seat, it transitions to HELD with a timestamp. You can implement a lazy evaluation check: whenever a seat is requested, check if its status is HELD and if the current time exceeds the hold timestamp plus 10 minutes. If it does, revert it to AVAILABLE. Another common edge case is handling concurrent cancellations. If a user cancels a booking, the system must thread-safely return that seat to the available pool and update the flight's available seat count without race conditions.
Acing the 30-Minute Code Review and Extension
Once the 90 minutes are up, the interviewer steps in to review your work. They will ask you to walk them through your architecture, starting from the domain models up to the driver class. They will run your code, plug in their own test cases, and actively try to break it by simulating concurrent requests or passing invalid inputs. Be ready to defend the time and space complexity of your in-memory search algorithms. If you used a simple list iteration to find flights between two cities, explain that it takes O(N) time. If they ask how to optimize it, explain how you would build a secondary index, such as a Map where the key is a concatenated string of 'Source-Destination' and the value is a List of Flights, reducing search time to O(1).
More often than not, the interviewer will ask you to add a new feature right on the spot to test your code's extensibility. A classic request is adding 'Waitlist' functionality for fully booked flights. If your code is tightly coupled, doing this live is going to be a nightmare. But if you designed your system well, the implementation is straightforward. You can add a Queue of User objects to the Flight entity. When a user tries to book a full flight, you push them onto the queue. Then, you modify your cancelBooking method: after freeing up a seat, check if the waitlist queue is empty. If it is not, pop the first user and automatically assign them the newly freed seat. Implementing this cleanly in under 15 minutes proves that your architecture is robust and that you can adapt to changing requirements under pressure.
Frequently asked questions
What language should I use for the Cleartrip machine coding round?
You are free to use any object-oriented language, including Java, C++, Python, or C#. That said, Java is highly recommended because of its robust java.util.concurrent utilities and how seamlessly it maps to standard Low Level Design patterns.
Do I need to write unit tests?
Usually, a comprehensive Driver class with a main method that hits all the edge cases is enough. Explicit JUnit or TestNG tests are a nice bonus, but you should absolutely prioritize finishing the core logic and concurrency handling first.
Is it okay if my code doesn't compile?
Not at all. Working, compilable code is a strict hard requirement for this round. You are much better off having fewer features that work perfectly and compile than a complete feature set that throws compilation errors.
How complex should the search algorithms be?
For an in-memory search, sticking to basic data structures like HashMaps and Lists is perfectly fine. You do not need to build complex spatial trees unless the interviewer specifically asks for them, though you should be ready to explain how you would optimize the search using indexing if the system scaled.
Related comparisons
See AcePromptAI in action
Watch how AcePromptAI supports a real technical round - structured answers, tuned to your resume, in real time.
Nail your next machine coding round with real-time AI guidance. Try AcePrompt today.
Get started