Parking-Lot Occupancy Timeline
Updated
Problem statement
Each parking record is an integer pair [enter, exit]. A vehicle occupies the lot at integer time x exactly when enter <= x < exit.
Given the records and a non-negative integer t, return the number of vehicles in the lot at every integer time from 0 through t, inclusive.
Records may begin before zero or end after t. A zero-duration record contributes nothing.
Function
occupancyTimeline(records: int[][], t: int) → int[]Examples
Example 1
records = [[1,3],[2,5],[4,5]]t = 4return = [0,1,2,1,2]The half-open intervals are active at the listed integer times.
Example 2
records = [[-2,1],[0,3],[3,3]]t = 3return = [2,1,1,0]The first record is still active at time zero, and the zero-duration record contributes nothing.
Example 3
records = []t = 2return = [0,0,0]An empty record set leaves the lot empty.
Constraints
0 <= records.length <= 200000.- Each row has exactly two integers and satisfies
enter <= exit. 0 <= t <= 1000000.- Times lie in the signed 32-bit range.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Peak Chat Load Across AgentsCresta · PHONE SCREENCresta interview questions
- Majority Labels over Audio IntervalsNooks · PHONE SCREEN
- Earliest Time to Schedule a MeetingMathWorks · OAMathWorks interview questions
- Earliest Meeting Start on a 24-Hour ClockIMC Trading · OAIMC Trading interview questions
- Earliest Time to Schedule a MeetingMicrosoft · OAMicrosoft interview questions
- Earliest Common Meeting StartVisa · OAVisa interview questions
- Smallest Most-Lit Street PositionHudson River Trading · OAHudson River Trading interview questions
- Most Visited Sprint MarkerChubb · OAChubb interview questions
- Earliest Common Meeting TimeZipRecruiter · OAZipRecruiter interview questions
- File Download Coverage PercentagePersona · OAPersona interview questions