Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Given a list of integers, return whether the largest number is bigger than the second-largest number by more than two times.
- For example, given the list [3, 9, 6], you should return false, since 9 is not bigger than 12 (2 times 6).
- Given the list [6, 3, 15], you should return true, since 15 is bigger than 12 (2 times 6).
- Example 1
- Input
- nums = [3, 6, 9]
- Output
- False
- Explanation
- 9 is not bigger than 2 * 6.
- '''
- def solve(nums):
- first = sorted(nums)
- max = first.pop()
- second = sorted(first)
- max2 = second.pop()
- if max > 2 * max2:
- return True
- return False
- # MAIN FUNCTION
- list1 = [6, 3, 15]
- print(solve(list1))
- list2 = [6, 3, 12]
- print(solve(list2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement