Collision
Problem Overview
- Determine which toy cars remain after all collisions when cars moving in opposite directions meet: the lower strength explodes; equal strengths both explode.
- Input: n, direction[i] in {1, -1}, strength[i]; Output: strengths of cars left in non-decreasing order.
- Constraints: n ≤ 2×10^5, strength[i] ≤ 10^9.
- Domain: collisions of cars on a single road with direction and impact strength.
- From Mathworks interviews; a coding interview problem and common interview question.
Example
Unlock to view complete problem details
and practice with sample input/output
Was this article helpful?
View Test Cases & Run Code requires membership
Input Variables
Execution Result:
