Car Pooling
Signals to notice
Brute force first
Simulate each mile. Extremely slow for long routes. It is a fair place to begin because it matches the surface of the question, yet it does not capture the deeper structure that makes the problem simpler.
The key insight
Difference array: for each trip, +passengers at start, -passengers at end. Sweep left to right summing — if any position exceeds capacity, return false. or with event sorting. The goal is not to be clever for its own sake, but to remember the one relationship that keeps the solution grounded as you move forward.
What must stay true
The difference array captures the net change at each position. A prefix sum gives the actual passenger count at each mile. If it ever exceeds capacity, car pooling isn't possible. If that remains true after every update, the rest of the reasoning has a stable place to stand.
Easy way to go wrong
Not using a difference array — simulating each trip independently or checking each mile directly is much slower. When the code becomes mechanical before the idea is clear, small edge cases start breaking the whole story.