Guest User

Untitled

a guest
Nov 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. return [max(a, b).pop(0) for _ in a+b] # this gives the max number that could be generated from 2 arrays while retain the relative order
  2.  
  3.  
  4. """
  5. this gives the max number that can be generated with length of k while keeping the relative order
  6. """
  7. def getMax(self, nums, k):
  8. n = len(nums)
  9. ans = []
  10. while k > 0:
  11. start = 0 if len(ans) == 0 else (ans[-1] + 1)
  12. end = n - k + 1
  13. ans.append(nums[start:end].index(max(nums[start: end])) + start)
  14. k -= 1
  15. return [nums[i] for i in ans]
Add Comment
Please, Sign In to add comment