Largest Number At Least Twice of Others
EasyArrays & Hashinggreedy
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given an integer array nums whose largest value occurs **exactly once**.
Check whether that largest value is at least **twice** as large as every other element. If it is, return the index of the largest element; otherwise return -1. A single-element array trivially qualifies, so return 0.
Examples
Input: nums = [3,6,1,0]
Output: 1
6 is at least double 3, 1 and 0; it sits at index 1.
Input: nums = [1,2,3,4]
Output: -1
4 is less than twice 3.
Constraints
- 1 <= nums.length <= 50
- 0 <= nums[i] <= 100
- The maximum value in `nums` is unique
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.