Skip to the code
+25 XP

#588 Shuttle Seats Never Exceeded

medium

A ride-sharing app plans one shuttle that drives in one direction along a road. Each booking is [riders, from, to]: riders people get on at kilometer from and off at kilometer to. People getting off at a stop leave before new people get on there.

Write fitsInShuttle(bookings, seats) that returns true if the shuttle never carries more than seats people at once, and false otherwise.

Example 1

Input: bookings = [[2,1,5],[3,3,7]], seats = 4
Output: false

Between kilometers 3 and 5 there are 2 + 3 = 5 riders.

Example 2

Input: bookings = [[2,1,5],[3,5,7]], seats = 3
Output: true

The first group leaves at 5 before the second group gets on.

Constraints

  • 0 <= bookings.length <= 10^5
  • 1 <= riders <= 100
  • 0 <= from < to <= 10^5
  • 1 <= seats <= 10^5
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).