Room Occupancy at Query Times
Updated
Problem statement
You are given room visits as pairs [entry, exit] and an array queryTimes. Calculate how many visits are in progress at each query time.
For this exercise, each row represents a separate person's visit, and the person is inside exactly when entry <= time < exit. Identical intervals count separately. Return the counts in the original order of queryTimes.
Function
countRoomOccupancy(visits: int[][], queryTimes: int[]) → int[]Examples
Example 1
visits = [[1,5],[3,7],[5,8]]queryTimes = [0,3,5,7,8]return = [0,2,2,1,0]At time 5, the first visit has ended and the third has begun. At time 8, every visit has ended.
Example 2
visits = []queryTimes = [4,4]return = [0,0]An empty visit list leaves the room empty at every query.
Example 3
visits = [[2,4],[2,4]]queryTimes = [4,2,3]return = [0,2,2]The two equal intervals describe separate visits. Answers preserve query order.
Constraints
- For this exercise, assume
0 <= visits.length <= 100and0 <= queryTimes.length <= 500. - Every visit has exactly two integers with
0 <= entry < exit <= 10^9. - Every query time is between
0and10^9. Inputs need not be sorted.
More WhatNot Onsite Interview questions
- Merge Sorted Squares of Two ArraysPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Adjacent Pair and Run RemovalPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Search a 2D MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Detect Blocked Chat MessagesPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
- Detect Blocked Chat PhrasesPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
- Minimum Remove to Make Valid ParenthesesONSITE INTERVIEW · Seen Dec 2024
- Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2024
- Merge Two Sorted ListsONSITE INTERVIEW · Seen Jul 2024
- Number of Submatrices That Sum to TargetONSITE INTERVIEW · Seen Jul 2024
Similar questions at other companies
- 3Sum SmallerSalesforce · ONSITE INTERVIEW
- Maximize the Minimum Distance Between RobotsAmazon · ONSITE INTERVIEW
- Streaming Triple Packing by Size ThresholdGoogle · ONSITE INTERVIEW
- Maximum Total Length of Non-Overlapping IntervalsBloomberg LP · ONSITE INTERVIEW
- HTTP Log QueriesDatadog · PHONE SCREEN · ONSITE INTERVIEW
- Smallest Common Integer in Sorted ListsMotive · ONSITE INTERVIEW
- Russian Doll EnvelopesInMobi · ONSITE INTERVIEW
- Find Unmet Users With Shared InterestsPalantir · ONSITE INTERVIEW
- Count Later Lower ReadingsRippling · ONSITE INTERVIEW
- Russian Doll EnvelopesAirbnb · ONSITE INTERVIEW