Problem statement

https://leetcode.com/problems/largest-number-at-least-twice-of-others/

Solution

Just do what is asked: find maximum number and then iterate over all numbers and check if they at least twice smaller or not.

Complexity

Time complexity is O(n), space complexity is O(1).

Code

class Solution:
    def dominantIndex(self, nums):
        m = max(nums)
        if all(m >= 2*x for x in nums if x != m):
            return nums.index(m)
        return -1