Who Is in the Room?
Updated
Problem statement
You are given an event log. Process the events in their given order. Find the final room status of every person named in the log.
For this exercise, each event is [name, action], where action is enter or exit. Everyone starts outside. An entry sets that person's state to IN; an exit sets it to OUT. Repeating the same action is allowed and does not change its meaning.
Return one row [name, state] for every person appearing in the log, including people who finish outside. Sort rows alphabetically by name. The answer for an empty log is an empty array.
Function
roomPresence(events: String[][]) → String[][]Examples
Example 1
events = [["amy","enter"],["bob","enter"],["amy","exit"]]return = [["amy","OUT"],["bob","IN"]]Amy's latest event is an exit; Bob's is an entry. Rows are ordered by name.
Example 2
events = [["zoe","exit"],["zoe","enter"],["zoe","enter"]]return = [["zoe","IN"]]An entry sets the state to IN. Repeated entries keep the same state.
Example 3
events = []return = []No observed people means no output rows.
Constraints
- For this exercise, assume
0 <= events.length <= 200. - Every event has exactly two strings.
- Names contain
1to20lowercase English letters. - Actions are exactly
enterorexit.
More WhatNot Phone Screen 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
- User Journey Paths from a Log StreamPHONE SCREEN · Seen Nov 2026
- Reachable Exits in an Obstacle GridPHONE SCREEN · Seen Oct 2026
- Palindrome with One DeletionPHONE SCREEN · Seen Oct 2026
- Search a 2D MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Attraction Route Without Reusing TrailsPHONE SCREEN · Seen Sep 2026
- Earliest Car for Each PassengerPHONE SCREEN · Seen Sep 2026
- Minimum Stores for a Shopping ListPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Number of AtomsAmazon · ONSITE INTERVIEW
- Mutual-Friend Referral RecommendationsFireworks AI · PHONE SCREEN · ONSITE INTERVIEW
- Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Log Analyzer: Busiest Service in a Rolling WindowByteDance · PHONE SCREENByteDance interview questions
- Merchant Payout Scheduler, Part 2: Per-Merchant SchedulesStripe · PHONE SCREENStripe interview questions
- Longest Consecutive SequenceJP Morgan Chase · PHONE SCREENJP Morgan Chase interview questions
- Top K Frequent Elements with a Recency TiebreakSwiggy · PHONE SCREEN