Largest Number At Least Twice Others

Easy

Description

Find if the largest element in the array is at least twice as large as all other numbers. Return the index of largest element, or -1 if not.

Examples

Input:nums = [3,6,1,0]
Output:1
Explanation:

6 is the largest and 6 >= 2*3.

Input:nums = [1]
Output:0
Explanation:

With only one element, it is trivially the largest at index 0.

Input:nums = [2,8,4,1]
Output:1
Explanation:

8 is the largest element at index 1. Checking: 8 >= 2*4 (8), 8 >= 2*2 (4), and 8 >= 2*1 (2). All conditions are satisfied.

Constraints

  • 1 ≤ nums.length ≤ 50

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!