Approach #1: Linear Scan [Accepted]

Intuition and Algorithm

Scan through the array to find the unique largest element m, keeping track of it's index maxIndex.

Scan through the array again. If we find some x != m with m < 2*x, we should return -1.

Otherwise, we should return maxIndex.

Complexity Analysis

  • Time Complexity: where is the length of nums.

  • Space Complexity: , the space used by our int variables.


Analysis written by: @awice.