Advertisement
makispaiktis

BinarySearchIO - Largest Number By Two Times

Aug 25th, 2020 (edited)
1,920
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. '''
  2. Given a list of integers, return whether the largest number is bigger than the second-largest number by more than two times.
  3. For example, given the list [3, 9, 6], you should return false, since 9 is not bigger than 12 (2 times 6).
  4. Given the list [6, 3, 15], you should return true, since 15 is bigger than 12 (2 times 6).
  5. Example 1
  6. Input
  7. nums = [3, 6, 9]
  8. Output
  9. False
  10. Explanation
  11. 9 is not bigger than 2 * 6.
  12. '''
  13.  
  14. def solve(nums):
  15.     first = sorted(nums)
  16.     max = first.pop()
  17.     second = sorted(first)
  18.     max2 = second.pop()
  19.     if max > 2 * max2:
  20.         return True
  21.     return False
  22.  
  23. # MAIN FUNCTION
  24. list1 = [6, 3, 15]
  25. print(solve(list1))
  26. list2 = [6, 3, 12]
  27. print(solve(list2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement