Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from itertools import cycle
- def find_strongest_eggs(*args):
- strongest = []
- eggs: list = args[0]
- sub_lists = [[] for _ in range(args[1])]
- for x in cycle(sub_lists):
- if eggs:
- x.append(eggs.pop(0))
- else:
- break
- for x in sub_lists:
- condition_1 = False
- condition_2 = False
- middle = int(len(x) / 2)
- middle_egg = x[middle]
- left = middle - 1
- right = middle + 1
- if middle_egg > x[right] and middle_egg > x[left]:
- condition_1 = True
- while 0 <= left and right < len(x):
- if x[right] > x[left]:
- right += 1
- left -= 1
- condition_2 = True
- else:
- condition_2 = False
- break
- if condition_1 and condition_2:
- strongest.append(middle_egg)
- return strongest
- test = ([-1, 7, 3, 15, 2, 12], 2)
- print(find_strongest_eggs(*test))
- test = ([-1, 0, 2, 5, 2, 3], 2)
- print(find_strongest_eggs(*test))
- test = ([51, 21, 83, 52, 55], 1)
- print(find_strongest_eggs(*test))
Advertisement
Add Comment
Please, Sign In to add comment