Check Capacity Along Eastbound Trips

Quick Overview

Check Capacity Along Eastbound Trips. A car drives only east and starts empty with the given capacity.

Check Capacity Along Eastbound Trips

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem A car drives only east and starts empty with the given capacity. Each trip `[passengers,from,to]` requires carrying that many people from from to to. At a shared location, dropoffs happen before pickups. Return whether every trip can be served without ever exceeding capacity. ```cpp class Solution { public: bool carPooling(vector<vector<int>>& trips, int capacity); }; ``` ### Examples **Example 1:** ```text Input: trips = [[3,0,2],[3,2,5]], capacity = 3 Output: true Explanation: The first group leaves at2 before the second group boards. ``` **Example 2:** ```text Input: trips = [[2,0,4],[2,3,5]], capacity = 3 Output: false Explanation: Four passengers overlap between locations3 and4. ``` ### Constraints - There are 1 to 1000 trips, each with three entries. - Each group has 1 to 100 passengers. - Endpoints are integers with `0 <= from < to <= 1000`. - Capacity is an integer between 1 and 100000. ### Contract considerations The car cannot reverse direction. Every trip has from<to. ```hint Read the boundary condition At a location shared by two trips, which passengers have already left before new passengers board? ``` ### Boundary reminders The car cannot reverse direction. Every trip has from<to.

Overview: Check Capacity Along Eastbound Trips. A car drives only east and starts empty with the given capacity.

Amazon logo
Amazon
Source window: 0–3 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

A car drives only east and starts empty with the given capacity. Each trip [passengers,from,to] requires carrying that many people from from to to. At a shared location, dropoffs happen before pickups. Return whether every trip can be served without ever exceeding capacity.

class Solution {
public:
    bool carPooling(vector<vector<int>>& trips, int capacity);
};

Examples

Example 1:

Input: trips = [[3,0,2],[3,2,5]], capacity = 3
Output: true
Explanation: The first group leaves at2 before the second group boards.

Example 2:

Input: trips = [[2,0,4],[2,3,5]], capacity = 3
Output: false
Explanation: Four passengers overlap between locations3 and4.

Constraints

  • There are 1 to 1000 trips, each with three entries.
  • Each group has 1 to 100 passengers.
  • Endpoints are integers with 0 <= from < to <= 1000 .
  • Capacity is an integer between 1 and 100000.

Contract considerations

The car cannot reverse direction. Every trip has from<to.

Boundary reminders

The car cannot reverse direction. Every trip has from<to.