1094. Car Pooling
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 56% Topics: Array, Sorting, Heap (Priority Queue), Simulation, Prefix Sum
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(nlogn)
# Space: O(n)
class Solution(object):
def carPooling(self, trips, capacity):
"""
:type trips: List[List[int]]
:type capacity: int
:rtype: bool
"""
line = [x for num, start, end in trips for x in [[start, num], [end, -num]]]
line.sort()
for _, num in line:
capacity -= num
if capacity < 0:
return False
return True
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions