NASA is studying an unnatural tidal wave phenomenon on a distant planet. They've recorded a sequence of incoming waves represented by an array w
. Each wave has a direction and strength:
- The absolute value of each number represents the wave's height in meters.
- The sign indicates the direction: positive means flowing eastward, negative means flowing westward.
- The index in the array represents the wave's position in the observation sequence.
When waves flowing in opposite directions meet, they create a collision. In a collision:
- If one wave is taller than the other, the smaller wave dissipates completely while the taller wave continues its course.
- If both waves are of equal height, they neutralize each other and both dissipate.
- Waves flowing in the same direction never interact with each other.
Given the initial wave measurements, determine which waves will remain after all possible collisions have occurred.