Leetcide problem doubt


Here in the solution why we are addingt the start location and subtracting the end location

What we are doing basically is keeping track of the number of passengers at any given time as a prefix sum. So if a trip i starts at t1, we add the passengers at time t1 for the trip. Now they stay in the car till time t2, so we subtract them at t2. Now at any point just simply check if sum is greater than capacity or not.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.