Largest Number At Least Twice of Others Problem

Largest Number At Least Twice of Others Problem — ExecCode Easy DSA Practice

Solve the Largest Number At Least Twice of Others problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given an integer array nums where the largest integer is unique. Your task is to determine whether the largest element in the array is at least twice as much as every other number in the array. If it is, return the index of the largest element, or return -1 otherwise.

Examples

Input {"nums": [3, 6, 1, 0]}; Output 1. Input {"nums": [1, 2, 3, 4]}; Output -1

Constraints

2 <= nums.length <= 50 0 <= nums[i] <= 100 The largest element in nums is unique.

Practice Largest Number At Least Twice of Others free on ExecCode. Browse DSA problems, topic map, and placement guides.