Time of Maximum Mall Occupancy
Updated
Problem statement
Each row of events is [count,timestamp,direction]. Direction 1 means that many people enter a mall; direction 0 means they exit. Return the recorded timestamp when the mall has its maximum occupancy.
For this exercise, assume the mall starts empty and rows may be unordered. Process all events with the same timestamp together. Measure occupancy only after applying every event at that time. Do not count a temporary peak caused by processing those rows in a particular order. Repeated records contribute separately.
For this exercise, assume aggregate occupancy never becomes negative after a timestamp batch. If several recorded timestamps share the maximum, return the smallest one. Empty input returns -1. Accumulate people counts with wide integer arithmetic.
Function
maxOccupancyTime(events: int[][]) → intExamples
Example 1
events = [[12,1,1],[5,2,0],[7,1,1],[5,1,0]]return = 1At timestamp 1, twelve plus seven enter and five exit, leaving fourteen. The exit at timestamp 2 leaves nine, so the maximum occurs at 1.
Example 2
events = [[2,9,1],[2,5,1],[2,8,0]]return = 5The input is unordered. Occupancy is two at 5, zero at 8 and two at 9; the earliest maximum is 5.
Constraints
- For this exercise, assume
0 <= events.length <= 1000. Every row has exactly three integers. - For this exercise, assume
1 <= count <= 1000000000,0 <= timestamp <= 1000000000, and direction is0or1. - The sum of all changes at or before any recorded timestamp is nonnegative. Occupancy may exceed signed 32-bit range.
More Wayfair interview questions
- Container With Most WaterPHONE SCREEN · Seen Sep 2026
- Assign Distinct Letter Values to Minimize XORPHONE SCREEN · Seen Sep 2026
- First Three Badge Times per UserPHONE SCREEN · Seen Apr 2022
- Longest Common Contiguous User ActionsPHONE SCREEN · Seen Apr 2022
- Count a Person’s Distinct FriendsPHONE SCREEN · Seen Mar 2022
- Word Path Moving Only Right or DownPHONE SCREEN · Seen Mar 2022
- Tree Nodes with Zero or One ParentPHONE SCREEN · Seen Sep 2021
- UCB1 Multi-Armed Bandit TraceONSITE INTERVIEW · Seen Sep 2026
- Moving Cost by Volume and CategoryONSITE INTERVIEW · Seen Sep 2026
- DFS Subsequences of a String (For MLE)OA · Seen Sep 2024
Similar questions at other companies
- Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
- Fair Capped Money DistributionGusto · PHONE SCREEN · ONSITE INTERVIEWGusto interview questions
- Merge IntervalsApple · OA · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
- Merge Sorted Squares of Two ArraysWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Merge Overlapping IntervalsAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Merge Weekday and Time IntervalsNextdoor · PHONE SCREENNextdoor interview questions
- Peak Chat Load Across AgentsCresta · PHONE SCREENCresta interview questions