First Three Badge Times per User
Updated
Problem statement
Each row of records is [userID,timestamp,action], recording either clockin or clockout. Return the first three times for every represented user, or all of that user's times if they have fewer than three.
For this exercise, assume first means the earliest numeric timestamps, regardless of input order. Both actions count. Every occurrence counts separately, including identical rows or events with equal timestamps. No matching or alternating action sequence is required.
For this exercise, assume the result contains one row [userID,time1,...] per user. Treat IDs as complete case-sensitive strings, so different leading-zero spellings identify different users. Sort rows by ASCII user ID and selected times numerically ascending. Write times as decimal strings without leading zeros. Empty input returns an empty array.
Function
firstThreeTimes(records: String[][]) → String[][]Examples
Example 1
records = [["A","1","clockin"],["B","2","clockout"],["C","3","clockin"]]return = [["A","1"],["B","2"],["C","3"]]Each represented user has only one event; both action types contribute a timestamp.
Example 2
records = [["Ada","9","clockout"],["Ben","4","clockin"],["Ada","3","clockin"],["Ada","3","clockout"],["Ada","1","clockin"],["Ben","2","clockout"]]return = [["Ada","1","3","3"],["Ben","2","4"]]Ada has four records, so keep 1,3,3. Ben has two and retains both 2,4. Rows are ordered by user ID.
Constraints
- For this exercise, assume
0 <= records.length <= 200. Each row has exactly three strings. - For this exercise, assume user IDs contain
1through30ASCII letters, digits or underscores. IDs are case-sensitive. - For this exercise, assume timestamps have
1through10decimal digits, may have leading zeros, and have values from0through1000000000. Actions areclockinorclockout; fields contain no whitespace.
More Wayfair interview questions
- Container With Most WaterPHONE SCREEN · Seen Sep 2026
- Assign Distinct Letter Values to Minimize XORPHONE SCREEN · Seen Sep 2026
- Time of Maximum Mall OccupancyPHONE 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
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
- Mutual-Friend Referral RecommendationsFireworks AI · PHONE SCREEN · ONSITE INTERVIEW
- 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
- User Journey PathsWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot 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