Corporate Flight Bookings
MediumArrays & Hashingprefix sum
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
There are n flights numbered 1 through n. Each entry bookings[i] = [first, last, seats] reserves seats seats on every flight from first to last, inclusive.
Return an array answer of length n where answer[j] is the total number of seats reserved on flight j + 1.
Aim for O(n + bookings.length) time.
Examples
Input: bookings = [[1,2,5],[2,4,3]], n = 4
Output: [5,8,3,3]
Flight 1 gets 5, flight 2 gets 5 + 3, flights 3 and 4 get 3.
Input: bookings = [[3,3,7]], n = 3
Output: [0,0,7]
Only flight 3 is booked.
Constraints
- 1 <= n <= 2 * 10^4
- 1 <= bookings.length <= 2 * 10^4
- `bookings[i].length == 3`
- 1 <= first <= last <= n
- 1 <= seats <= 10^4
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.