You are given an integer array nums where the largest integer is unique. Determine whether the largest element in the array is at least twice as much as every other number in the array. If it is, return the index of the largest element, or return -1 otherwise.
You are given an integer array nums where the largest integer is unique. Determine whether the largest element in the array is at least twice as much as every other number in the array. If it is, return the index of the largest element, or return -1 otherwise.
Example 1:
Input: {"nums":[3,6,1,0]}
Output: 1
Constraints:
2≤nums.length≤50
0≤nums[i]≤100
The largest element in nums is unique.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[3,6,1,0]}
Keep only two values while scanning: the largest (first) and the runner-up (second). Both start at -1, below every allowed value.