Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- """
- this gives the max number that can be generated with length of k while keeping the relative order
- """
- def getMax(self, nums, k):
- n = len(nums)
- ans = []
- while k > 0:
- start = 0 if len(ans) == 0 else (ans[-1] + 1)
- end = n - k + 1
- ans.append(nums[start:end].index(max(nums[start: end])) + start)
- k -= 1
- return [nums[i] for i in ans]
Add Comment
Please, Sign In to add comment