A charity gala hands out n prize envelopes to contestants, each holding a non-negative integer amount of prize money. The organizers want to know whether one contestant's prize completely dominates the field: specifically, whether the largest prize amount is at least twice as large as every other contestant's prize. It is guaranteed that the largest prize amount in the list is unique (no ties for the top prize). If the largest prize dominates in this way, report its 0-indexed position in the list; otherwise, report that no such dominant prize exists.
Print a single integer: the 0-indexed position of the largest prize if it is at least twice every other prize in the list, otherwise print -1.
Example 1
Input
4 3 6 1 0
Expected
1
Explanation
The largest prize is 6, at index 1. Checking against every other prize: 6 >= 2*3 (6>=6, true), 6 >= 2*1 (6>=2, true), 6 >= 2*0 (6>=0, true). Since 6 dominates all others, the answer is its index, 1.
Example 2
Input
4 1 2 3 4
Expected
-1
Explanation
The largest prize is 4, at index 3. It must be at least twice the next largest prize, 3, but 4 < 2*3 = 6, so it fails to dominate. The answer is -1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →