Rounds Until a Release Train Stops Evicting Out-of-Order Builds
Last updated: November 29, 2026
Quick Overview
A release train is a list of build numbers. In each round, every build whose number is smaller than the build directly ahead of it is evicted, all at once. Return how many rounds pass until a round evicts nothing.
0
0
0 solved
A release train is a list of build numbers. In each round, every build whose number is smaller than the build directly ahead of it is evicted, all at once. Return how many rounds pass until a round evicts nothing.
A Google onsite problem where the direct round-by-round simulation is O(n^2) and the expected solution computes each element's eviction round with a monotonic stack. Interviewers want the simulation first as a reference, then a clear argument for the stack recurrence.
What the Interviewer Expects
- Write the simultaneous-removal simulation correctly as a baseline
- Observe each element is evicted by the nearest larger element to its left
- Compute an element's eviction round as 1 + max rounds of elements popped between them
- Elements with no larger element to the left are never evicted
- Achieve O(n) with a monotonic stack
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return the list of builds remaining after all rounds.
- What if a build is evicted when it is smaller than either neighbor?
- Can you prove the stack recurrence by induction on position?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list nums. In a round, remove all nums[i] with nums[i-1] > nums[i], comparing against the list as it was at the start of the round. Output the number of rounds that remove at least one el...
High-Level Design
Baseline: repeat building the survivor list until nothing changes, O(n^2) worst case.
Stack approach: process left to right with a stack of (value, rounds_to_evict), keeping values strictly decreas...