Search⌘ K
AI Features

Problem: Largest Number At Least Twice of Others

Explore how to solve the problem of finding whether the largest element in an integer array is at least twice as big as all other elements. Learn to apply linear search efficiently to identify the largest number and validate the condition in two passes, with a clear understanding of the algorithm's time and space complexity.

Statement

Given an integer array nums, in which the largest element is guaranteed to be unique, determine whether this largest element is at least twice as large as every other element in the array.

If the condition holds, return the index of the largest element. Otherwise, return 1-1.

Constraints:

  • 22 \leq nums.length 50\leq 50

  • 00 \leq ...