Skip to content

Commit

Permalink
Create 853-Car-Fleet.py
Browse files Browse the repository at this point in the history
  • Loading branch information
neetcode-gh authored Dec 26, 2021
1 parent 2038bd7 commit ca0e9c2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions 853-Car-Fleet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Solution:
def carFleet(self, target: int, position: List[int], speed: List[int]) -> int:
pair = [[p, s] for p, s in zip(position, speed)]

stack = []
for p, s in sorted(pair)[::-1]: # Reverse Sorted Order
stack.append((target - p) / s)
if len(stack) >= 2 and stack[-1] <= stack[-2]:
stack.pop()
return len(stack)

0 comments on commit ca0e9c2

Please sign in to comment.