Online Counts over Time
Updated
Problem statement
Given intervals, where each row is a half-open time interval [start,end) during which one person is online, return the online count over time as rows [start,end,count].
Each row is a longest stretch of time where the count stays the same and is above zero. Sort rows by start time. All starts and ends at the same time take effect together. A zero-length interval adds nothing. If nobody is ever online, return an empty matrix.
Function
onlineCounts(intervals: int[][]) → int[][]Examples
Example 1
intervals = [[1,4],[2,5],[4,6]]return = [[1,2,1],[2,5,2],[5,6,1]]One person is online on [1,2), two on [2,5), and one on [5,6). At time 4 one interval ends as another starts, so the count does not change.
Example 2
intervals = [[1,2],[4,5]]return = [[1,2,1],[4,5,1]]Nobody is online during [2,4), so that gap is left out. Each interval becomes its own row with a count of one.
Constraints
- 0 <= intervals.length <= 10000
- Every interval row has exactly 2 entries.
- 0 <= intervals[i][j] <= 10^9
- Every row is [start,end] with start <= end.
More Apple Phone Screen questions
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Topological OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Subarray Product Less Than KPHONE SCREEN · Seen Nov 2026
- Evaluate DivisionPHONE SCREEN · Seen Nov 2026
- Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
- Validate a BST with a Custom ComparisonPHONE SCREEN · Seen Nov 2026
- Design a Food Rating SystemPHONE SCREEN · Seen Oct 2026
- Days Until Poisoned Plants StabilizePHONE SCREEN · Seen Oct 2026
- Capture Surrounded Regions with Union-FindPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Peak Chat Load Across AgentsCresta · PHONE SCREENCresta interview questions
- Majority Labels over Audio IntervalsNooks · PHONE SCREEN
- Call Auction Clearing Price and Order FillsHudson River Trading · PHONE SCREENHudson River Trading interview questions
- Average Prices from Broker QuotesAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Subscription and Usage-Based Billing CalculatorStripe · OAStripe interview questions
- Count Lamps Lighting Each PointAirbnb · OAAirbnb interview questions
- Meeting Scheduling SystemHevo Data · ONSITE INTERVIEW
- Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
- Minimum Cost of Every K-Capable Model SetTikTok · OATikTok interview questions
- Maintain a Consistent-Hashing RingCohesity · ONSITE INTERVIEW
Apple interview experiences
- Apple SWE Phone Screen: Subarray Products: 1 Experience
- Apple New Grad SWE Java, Coding and Manager Rounds: 1 Experience
- Apple AI Coding and Related Interviews: 17 Experiences
- Apple India SWE New Grad Interviews: 5 Experiences
- Apple New Grad SWE Phone Screens: 12 Experiences (Part 3 of 3)
- Apple New Grad SWE and Embedded: 16 Experiences (Part 2 of 3)