Menu Close

Find whether the largest element in the array is at least twice as much as every other number in the array.

In a given integer array nums, there is always exactly one largest element. Find 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, otherwise return -1.

Input: nums = [3,6,1,0]
Output: 1

nums=list(map(int,input('Enter the array of nums: ').split(' ')))
l=sorted(nums,reverse=True)
if(len(l)>=2):
    if(l[0]>=(l[1]*2)):
        print(nums.index(l[0]))
    else:
        print(-1)
else:
    print(0)

Input_1:
Enter the array of nums: 0 0 0 1
Output:
3


Input_2:
Enter the array of nums: 0 1
Output:
1


Input_3:
Enter the array of nums: 1
Output:
0


Input_4:
Enter the array of nums: 1 2 3 4
Output:
-1


Input_5:
Enter the array of nums: 3 6 1 0
Output:
1


Morae!Q!

->Insert and Extend in list python
->Print Odd Numbers in range
->Compare List in python
->Find whether the largest element in the array is at least twice as much as every other number in the array.
->Find minimum cost to reach the top of the floor
->Word Count in Python
->Lower case to upper case in python
->Display Time in python
->Sum of Odd And Even in Python
->Surface Area of Walls
->Find the sum of squares of individual digits
->Print the given series – 1 1 2 6 24
->Minimum number of steps required to reach destination.
->Seconds to Days Hours Minutes
->Program to remove add “Hyphen” character in the entered string
->Remove the nth Index Character from a Non-Empty String
->Relational operator Question
->Check whether all the given numbers lies in range of x and y.
->Find the Armstrong numbers between the given range.