MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / carFleet

Method carFleet

python/0853-car-fleet.py:2–10  ·  view source on GitHub ↗
(self, target: int, position: List[int], speed: List[int])

Source from the content-addressed store, hash-verified

1class 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

Calls 1

popMethod · 0.45

Tested by

no test coverage detected