easyHeap / Priority QueueAmazonGoogle
Boulder Showdown Arena
Two heaviest boulders are hurled at each other every round. Equal weights annihilate; unequal weights leave a fragment that re-enters the arena.
Given an array of positive integer stone weights, repeatedly smash the two heaviest. Return the weight of the last remaining stone (or 0).
Choose approach
8
7
4
1
2
1
1/9
Narrationstep 1 of 9
Build initial max-heap from stones.
Variables
size=6
How to think about it
- Max-heap gives O(log n) access to the two heaviest each round.
- Equal weights -> both destroyed, nothing re-enters.
- Unequal -> only the diff re-enters.
Edge cases to catch in interview
- Single stone -> return itself.
- All equal pairs cancel out -> return 0.
Examples
Example 1
1{"stones":[2,7,4,1,8,1]}
Example 2
1{"stones":[1]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed