solved using v = d/t

This commit is contained in:
Jacob Delgado 2023-10-02 03:30:30 -07:00
parent ba769e5cf8
commit 7d38ee51ce
2 changed files with 24 additions and 5 deletions

View File

@ -21,10 +21,28 @@ class Solution(object):
:type speed: List[int] :type speed: List[int]
:rtype: int :rtype: int
""" """
fleets = [] n = len(speed)
for i,p in enumerate(position): # Create velocity with position and speed
print(f'{i}: {p}') v = [(position[i], speed[i]) for i in range(n)]
v.sort()
# Get Time based on displacement(distance from target) and speed
time = [float(target - v[i][0]) / v[i][1] for i in range(n)]
curr = float('-inf')
res = 0
# Find each fastest time of arrival per fleet based on new current time
for i in range(n - 1, -1, -1):
if time[i] > curr:
print(f'curr is {curr}: time is {time[i]}')
curr = time[i]
res += 1
return res
obj = Solution() obj = Solution()
print(obj.carFleet(12,[10,8,0,5,3],[2,4,1,1,3])) # 3 print(obj.carFleet(12,[10,8,0,5,3],[2,4,1,1,3])) # 3
print(obj.carFleet(10,[3],[3])) # 1
print(obj.carFleet(100,[0,2,4],[4,2,1])) # 1

View File

@ -1 +1,2 @@
0]*len(temperatures) print(obj.carFleet(10,[3],[3])) # 1
print(obj.carFleet(100,[0,2,4],[4,2,1])) # 1