Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def findMinimumMachinesSize(machineCapacity: list[int]) -> int:
- n = len(machineCapacity)
- if n == 0:
- return 0
- if n == 1:
- return 1
- deduplicated_list = [machineCapacity[0]]
- for i in range(1, n):
- if machineCapacity[i] != deduplicated_list[-1]:
- deduplicated_list.append(machineCapacity[i])
- len_dl = len(deduplicated_list)
- if len_dl <= 2:
- return len_dl
- final_list = [deduplicated_list[0]]
- for i in range(1, len_dl - 1):
- prev_kept_val = final_list[-1]
- current_val = deduplicated_list[i]
- next_potential_val = deduplicated_list[i+1]
- is_collinear = False
- if (prev_kept_val <= current_val <= next_potential_val) or \
- (prev_kept_val >= current_val >= next_potential_val):
- is_collinear = True
- if not is_collinear:
- final_list.append(current_val)
- final_list.append(deduplicated_list[-1])
- return len(final_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement