I recently went through onsite loop at Meta and I was asked two questions in one of the coding rounds
For example
[3,8,-2,-8]
Ans [-8,8]
Explanation : Up until -2, the problem is similar to question #1, but when we encounter -8, because the number on the top of the stack is 8, when they collide, they both change directions. -8 becomes 8 and the number on the top of the stack becomes -8 and moves in the opposite direction and crushes everything with smaller weight(and moving in opposite direction). So 3 in the stack gets crushed, resulting in [-8,8]
[6,2,4,-3,6,1,3,-5,-6, 4,-6]
Ans : [-6,-6,6,6]
I couldn't solve the second question. Does any one know how to approach this ?