Button Combination Detector
Updated
Problem statement
Button Combination Detector
A device produces a finite sequence of button events. Every event has the form down:BUTTON or up:BUTTON, where BUTTON is a case-sensitive label.
No buttons are pressed initially. Process the events in order and return true if, after any event, every label in requiredButtons is pressed at the same time. Other buttons may also be pressed. Return false if the required combination never occurs.
Pressing an already pressed button or releasing a button that is not pressed is a valid no-op.
Function
wasButtonCombinationPressed(events: String[], requiredButtons: String[]) → booleanExamples
Example 1
events = ["down:A","down:B","up:A"]requiredButtons = ["A","B"]return = trueAfter processing down:B, both A and B are pressed, so the required combination occurs.
Example 2
events = ["down:A","up:A","down:B","down:A"]requiredButtons = ["A","B"]return = trueThe first press of A is released before B is pressed. The final event presses A again while B is still down.
Example 3
events = ["down:A","down:C","up:C"]requiredButtons = ["A","B"]return = falseButton B is never pressed, so the required combination never occurs.
Constraints
1 ≤ events.length ≤ 100,0001 ≤ requiredButtons.length ≤ 100- Every required label is unique and matches
[A-Za-z0-9_-]{1,20}. - Every event is exactly
down:BUTTONorup:BUTTONfor a valid label.
More SpaceX interview questions
- Starlink Beam PlannerOA · PHONE SCREEN · Seen Nov 2026
- Timestamped Telemetry Stream DifferencesPHONE SCREEN · Seen Sep 2026
- Number of IslandsPHONE SCREEN · Seen Aug 2026
- Number of Islands IIPHONE SCREEN · Seen Aug 2026
- Pressure Chamber Linear InterpolationPHONE SCREEN · Seen Jun 2025
- Speed to Pressure LookupPHONE SCREEN · Seen Mar 2025
- Simplified Time-Based Key-Value StorePHONE SCREEN · Seen Nov 2023
- Rocket Component CostONSITE INTERVIEW · Seen Aug 2025
- DNA Sequence MatchOA · Seen Apr 2025
- Find the Duplicate NumberONSITE INTERVIEW · Seen Jan 2021
Similar questions at other companies
- Business Account KYC Verification — Parts 1–5Stripe · PHONE SCREENStripe interview questions
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Route Pattern MatcherGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- File Storage ServiceCresta · PHONE SCREENCresta interview questions
- String Interpolation with a Missing-Value ModeMongoDB · PHONE SCREENMongoDB interview questions
- Dasher Pay with Store Waits and Peak HoursDoorDash · PHONE SCREENDoorDash interview questions
- Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
- Fixed-Order Task Run Time With CooldownWaymo · PHONE SCREENWaymo interview questions
- Character Counts with Retried Remote WorkersCoalition · PHONE SCREEN
- Risk-Priority Detection StoreCrowdstrike · PHONE SCREENCrowdstrike interview questions