Largest At Least Twice Others
All values in nums are different. If the largest value is at least twice every other value, return its index. Otherwise return -1.
Example 1
nums [3,6,1,0]
returns 1
6 is at least twice 3, 1 and 0. Index 1.
Example 2
nums [1,2,3,4]
returns -1
4 is less than twice 3.
Constraints
1 <= len(nums) <= 300 <= nums[i] <= 100, all different
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Arrays problems
- Longest Increasing RunBeginner
- Max Consecutive OnesBeginner
- Peak So FarBeginner
- Running Sum of an ArrayBeginner
- Second AppearanceBeginner
- Shift Right and FillBeginner
- Shuffle the ArrayBeginner
- Sort by ParityBeginner