33 · Intervals

#1094 Car Pooling

Mediumsolve on LeetCode ↗

frequently reported atMetaAmazon

the problem

In plain words

A car drives east only and has capacity seats. trips[i] = [numPassengers, from, to]: those passengers get in at km from and out at km to. Can every trip be served? (This is the free cousin of Meeting Rooms II.)

in trips = [[2,1,5],[3,3,7]], capacity = 4

out false

Between km 3 and 5 there are 5 passengers.

in trips = [[2,1,5],[3,3,7]], capacity = 5

out true

  • 1 ≤ trips.length ≤ 1000
  • 1 ≤ numPassengers ≤ 100
  • 0 ≤ from < to ≤ 1000
  • 1 ≤ capacity ≤ 10⁵

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #253
      Meeting Rooms II
      Mediumin IntervalsLeetCode Premium
    2. #303