Search⌘ K
AI Features

Problem: Largest Number At Least Twice of Others

Explore how to implement a linear search algorithm in C# to identify the largest unique number in an array and verify if it is at least twice as large as every other element. Learn to perform two passes over the array for comparison, ensuring an optimal O(n) time and constant space solution.

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

  • ...