Problem · Heap

Last Robot Score

EasyNvidiaFULLTIMEPHONE 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.

Examples
01 · Example 1
scores = [10,4,7,3]
return = 2

10 and 7 leave 3, then 4 and 3 leave 1, then 3 and 1 leave 2. The last remaining robot has score 2.

02 · Example 2
scores = [8,5,3]
return = 0

8 and 5 leave 3, then the two 3s cancel.

Constraints

The competition always uses the two currently highest scores.

More Nvidia problems
drafts saved locally
public int lastRobotScore(int[] scores) {
    // write your code here
}
scores[10,4,7,3]
expected2
sign in to submit