Given trips where trips[i]=[numPassengers, from, to] and capacity, return true if you can pick up and drop off all passengers without exceeding vehicle capacity at any point.
Use a difference array (event-based). At each pickup location add passengers, at dropoff subtract. Scan from left and check if passengers ever exceed capacity.
- Create a diff[] array of size 1001 (max stop value).
- For each trip: diff[from] += num; diff[to] -= num.
- Scan diff[]: if running sum > capacity at any point, return false.
- Time Complexity: O(N + M) where M=1001
- Space Complexity: O(M)