Skip to the code
cf.
+10 XP

#55 Seat Bookings per Row

easy

A theater booking page has rows numbered 1 to n. Each group booking [first, last, seats] reserves seats seats in every row from first to last, both included.

Write seatsPerRow(n, bookings) that returns an array of length n where item i is the total seats reserved in row i + 1.

Example 1

Input: n = 4, bookings = [[1,3,5],[2,4,2],[4,4,7]]
Output: [5,7,7,9]

Row 2 gets 5 and 2 seats; row 4 gets 2 and 7 seats.

Example 2

Input: n = 3, bookings = []
Output: [0,0,0]

No bookings, so every row is empty.

Constraints

  • 1 <= n <= 10^5
  • 0 <= bookings.length <= 10^5
  • 1 <= first <= last <= n
  • 1 <= seats <= 10^4
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

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