FastPrepTime of Maximum Mall Occupancy
Problems/Time of Maximum Mall Occupancy

Time of Maximum Mall Occupancy

Wayfair logoWayfair● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The reported task of finding the time of maximum mall occupancy matches at about 90%. The four sample rows with symbols keep their counts, directions and order, with time1=1 and time2=2 as our mapping. The exit record says time2 while its text says time1, and this exercise follows the record. The starting occupancy, simultaneous batches, ties, the empty case and finite limits are our choices. Wayfair is the hiring company and Karat the provider.

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[][]) → int

Examples

Example 1

events = [[12,1,1],[5,2,0],[7,1,1],[5,1,0]]return = 1

At 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 = 5

The 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 is 0 or 1.
  • 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
All Wayfair interview questionsSee Wayfair hiring insights
Saved
class Solution {
    public int maxOccupancyTime(int[][] events) {
        // Write your code here.
        return -1;
    }
}
Checking account…