Reported March 2024
Trade Desksimulation

Flights

Reported by candidates from Trade Desk's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Trade Desk OA. Under 2s to a working solution.
Founder's read

Trade Desk asked this in March 2024, and it's a scheduling problem wrapped in flight language. You're given two arrays of departure times (outbound and return) and a count of round trips to complete. Each leg takes 100 minutes. The trick is that you always board the earliest available flight, and you need to return the time when the last round trip finishes. It sounds like simulation, but the real pattern is greedy selection with careful state tracking.

The problem

\ In the tale of two interconnected destinations served by flights, travelers aim to complete round trips between them. Flights in one direction take 100 minutes, and return flights take the same duration. Their goal is to determine the moment they'll finish their final round trip, assuming they always board the earliest available flight.\ \ To aid in their journey, the function \"tDeskFlights\" requires three inputs: two arrays of departure times (one for outbound flights and one for return flights) and the number of round trips planned. It then returns the time in minutes when the last round trip concludes.\ \ For original prompt, pls refer to source image ౨ৎ \

Reported by candidates. Source: FastPrep

Pattern and pitfall

The algorithm is straightforward greedy: for each round trip, pick the earliest outbound flight available after your current time, add 100 minutes to arrival, then pick the earliest return flight available after that arrival time, add another 100 minutes, and repeat. The catch is managing the indices into both arrays efficiently so you don't re-scan unnecessarily. Most candidates miss that you can't just use a single pointer per array if the arrays aren't sorted, or they reset pointers when they shouldn't. Build a simulation that steps through each round trip, tracks your current time, and increments the correct flight index as you consume flights. StealthCoder will catch the off-by-one errors or missed edge cases if you blank on state management during the live OA.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Flights cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Trade Desk's OA.

Trade Desk reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Flights FAQ

Is this a dynamic programming problem?+

No. There's no overlapping substructure or decision tree to memoize. It's pure greedy simulation. You consume flights in order and advance your time. The constraint is just the count of round trips, which bounds the loop.

What if I pick a flight that's already in the past?+

You can't. The problem guarantees you board the earliest available flight after your current time. So you scan the array from your current pointer and find the first departure time >= your current arrival time. If no flight exists, that shouldn't happen per the problem's intent, but handle it defensively.

Do the arrays have to be sorted?+

The problem doesn't state it explicitly. Assume they might not be. If unsorted, sort them first. If they're unsorted and you don't sort, you'll pick the wrong flight and your answer will be wrong. The safe move is always to sort both arrays upfront.

How do I handle the indices without rescanning?+

Keep a pointer for outbound and a pointer for return. After you board a flight, increment that pointer. Never reset. The next round trip starts from where you left off. If you're at a flight that departs before your current time, keep moving the pointer forward until you find one that doesn't.

What's the gotcha that trips people up?+

Forgetting that arrival time is departure plus 100, and then you need the earliest return flight after that arrival, not after your original departure. Also, mutating the arrays or losing track of which flights you've already boarded. Simulate cleanly and you'll avoid it.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Trade Desk.

OA at Trade Desk?
Invisible during screen share
Get it