Problem Brief
Last Robot Score
FULLTIMEPHONE SCREEN
Robots compete by score. While at least two robots remain, take the two robots with the highest scores and make them compete. If their scores are equal, both robots are eliminated. Otherwise, the robot with the larger score remains with its score reduced by the smaller score.
Return the score of the last remaining robot, or 0 if no robots remain.
1Example 1
Input
scores = [10,4,7,3]
Output
2
Explanation
10 and 7 leave 3, then 4 and 3 leave 1, then 3 and 1 leave 2. The last remaining robot has score 2.
2Example 2
Input
scores = [8,5,3]
Output
0
Explanation
8 and 5 leave 3, then the two 3s cancel.
Constraints
Limits and guarantees your solution can rely on.
The competition always uses the two currently highest scores.