You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This doesn't actually need a stack to be used, we can just store the maximum time someone on the right takes
class Solution:
def carFleet(self, target: int, position: List[int], speed: List[int]) -> int:
pos_vel = sorted(zip(position,speed), reverse=True)
max_seen = float("-inf")
ans = 0
for elem in pos_vel:
vel = elem[1]
pos = elem[0]
time = (target-pos)/vel
if max_seen < time:#I reach after everyone on my right, so i make one fleet
ans += 1
max_seen = time
return ans
The text was updated successfully, but these errors were encountered:
Thanks, @busi-reddy-karnati. Feel free to submit a PR adding this as a separate solution, I think we should keep the original for anyone coming from the YouTube video.
https://github.com/neetcode-gh/leetcode/blob/main/python/853-Car-Fleet.py
This doesn't actually need a stack to be used, we can just store the maximum time someone on the right takes
The text was updated successfully, but these errors were encountered: