Surviving Packets After Head-On Collisions on a Shared Link
Last updated: November 29, 2026
Quick Overview
Packets travel on a link: each has a size and a direction (positive moves right, negative moves left). When two meet head-on the smaller is dropped, equal sizes drop both; return the packets remaining after all collisions.
Meta
November 29, 20260
0
0 solved
Packets travel on a link: each has a size and a direction (positive moves right, negative moves left). When two meet head-on the smaller is dropped, equal sizes drop both; return the packets remaining after all collisions.
A Meta phone screen problem in the style of simulating traffic on a network link. The interviewer is checking that you identify which pairs can actually collide (only a right-mover followed by a left-mover) and implement the stack simulation without missing chained collisions.
What the Interviewer Expects
- Identify that only right-moving then left-moving pairs collide
- Use a stack of survivors and resolve each new left-mover against it
- Handle equal sizes destroying both packets
- Handle a left-mover destroying a chain of smaller right-movers
- State O(n) time
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 index in the original list of each survivor.
- What if packets also have speeds?
- How would you report the time of each collision?
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 p of non-zero integers; absolute value is size, sign is direction. All packets move at the same speed. Output: the list of survivors in original order. Packets moving the same direction ...
High-Level Design
Scan left to right, maintaining a stack of survivors so far. A right-mover is always pushed: nothing already seen can hit it. A left-mover may hit right-movers on top of the stack. While the top is a ...