Loading...
Loading...
You are given an integer array values of non-zero integers describing objects placed in a row. The absolute value of each entry is the object's size and its sign is its direction of travel: positive moves right, negative moves left. All objects move at the same speed.
When two objects meet, the smaller one is destroyed; if they are the same size, both are destroyed. Two objects moving in the same direction never meet.
Return the array of objects that remain after every collision has been resolved, in their original left-to-right order.
Input: values = [5,10,-5]
Output: [5,10]
Explanation: 10 and -5 meet and 10 survives. 5 and 10 move the same way and never meet.
Input: values = [8,-8]
Output: []
Explanation: 8 and -8 are the same size, so both are destroyed.
Input: values = [10,2,-5]
Output: [10]
Explanation: 2 and -5 meet and -5 survives; then 10 and -5 meet and 10 survives.
Input: values = [3,5,-6,2,-1,4]
Output: [-6,2,4]
Explanation: -6 destroys 3 and 5 and keeps moving left. 2 destroys -1. 2 and 4 both move right and never meet.
values.length ≤104values[i] ≤1000values[i] != 0