Method
carFleet
(self, target: int, position: List[int], speed: List[int])
Source from the content-addressed store, hash-verified
| 1 | class Solution: |
| 2 | def carFleet(self, target: int, position: List[int], speed: List[int]) -> int: |
| 3 | pair = [(p, s) for p, s in zip(position, speed)] |
| 4 | pair.sort(reverse=True) |
| 5 | stack = [] |
| 6 | for p, s in pair: # Reverse Sorted Order |
| 7 | stack.append((target - p) / s) |
| 8 | if len(stack) >= 2 and stack[-1] <= stack[-2]: |
| 9 | stack.pop() |
| 10 | return len(stack) |
Callers
nothing calls this directly
Tested by
no test coverage detected