Rounds Until a Ranking Feed Becomes Non-Decreasing
Last updated: November 29, 2026
Quick Overview
In each round, every item that is smaller than the item immediately before it is removed simultaneously; return the number of rounds until the list is non-decreasing.
Meta
November 29, 20260
0
0 solved
In each round, every item that is smaller than the item immediately before it is removed simultaneously; return the number of rounds until the list is non-decreasing.
A Meta onsite Hard framed as a feed-cleanup simulation where items out of rank order are dropped in parallel passes. The interviewer looks for the insight that each element's removal round depends on the rounds of the smaller elements between it and its nearest larger predecessor, computed with a monotonic stack.
What the Interviewer Expects
- Simulate a few rounds by hand to see the cascading pattern
- Note the O(n^2) simulation is too slow
- Assign each element the round in which it is removed
- Use a stack of (value, round) decreasing in value
- Return the maximum round
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 which items remain at the end.
- What if an item is removed when it is smaller than or equal to its predecessor?
- What if removals are not simultaneous but left to right?
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 a of integers, length up to 10^5. Each round, all indices i with a[i-1] > a[i] (in the current list) are deleted at once. Output: number of rounds until no deletion happens. An already...
High-Level Design
An element x is eventually removed by the nearest earlier element that is strictly larger (its killer), and only after every element between them has been removed. Elements between them are all less t...