Resolve Opposing Packet Collisions on a Single Network Line

Last updated: November 29, 2026

Quick Overview

Packets travel along a line, each with a signed size where the sign gives its direction (positive right, negative left); when two meet, the smaller is destroyed and equal sizes destroy each other. Return the packets that survive.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Packets travel along a line, each with a signed size where the sign gives its direction (positive right, negative left); when two meet, the smaller is destroyed and equal sizes destroy each other. Return the packets that survive.

A Microsoft technical screen simulation that looks like it needs a time-step loop but is really a stack problem. The interviewer checks whether you identify which pairs can ever collide and resolve chains of collisions in a single pass.

What the Interviewer Expects
  • Observe that only a right-moving packet followed by a left-moving one can collide
  • Keep survivors on a stack
  • Resolve a new left-moving packet against the stack top repeatedly
  • Handle equal sizes destroying both
  • Argue O(n) amortized time
Key Topics to Cover
stack
simulation
amortized analysis
arrays
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if packets have different speeds as well as sizes?
  • How would you also report the time of each collision?
  • How would you process the line as a stream from left to right with bounded memory?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input is a list of non-zero integers in positional order along the line. All packets move at the same speed. Positive means moving right, negative means moving left. When two meet, the one with the sm...

High-Level Design

Two packets can only meet if the left one moves right and the right one moves left. A left-mover followed by a right-mover separates, and same-direction packets never meet at equal speed. So scan left...


Submit Your Answer
Markdown supported

Related Questions