Reported February 2026
SpaceXhash table

Button Combination Detector

Reported by candidates from SpaceX's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live SpaceX OA. Under 2s to a working solution.
Founder's read

The SpaceX Button Combination Detector, reported in February 2026, looks like a warm-up. It isn't a trap, but one edge case breaks the naive version. You're simulating button events and checking whether all required buttons were held down at the same moment. The pattern is hash-table simulation. If you blank during the OA, StealthCoder runs invisibly as a safety net and hands you the logic. But this one is small enough to own in your head tonight.

The problem

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

Examples
Example 1
events = ["down:A","down:B","up:A"]
requiredButtons = ["A","B"]
return = true
After 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 = true
The 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 = false
Button B is never pressed, so the required combination never occurs.

Constraints
1 ≤ events.length ≤ 100,000
1 ≤ requiredButtons.length ≤ 100
Every required label is unique and matches [A-Za-z0-9_-]{1,20}.
Every event is exactly down:BUTTON or up:BUTTON for a valid label.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Keep a set of currently pressed buttons. Walk the events once. On down:X, add X. On up:X, remove X if present. After each event, check whether every required button is in the set. The naive trap is checking only at the end, or only after down events. Example 1 shows why: A is released after the combination already happened, so you must check as you go. Duplicate downs and stray ups are no-ops, and a set handles both for free. Cost matters too. With 100,000 events and up to 100 required buttons, rechecking all 100 every time is 10 million lookups, which is fine. Better, track a counter of required buttons currently pressed, updated only when a required button changes state. Parse with a split on the colon and keep labels case-sensitive. If you freeze live, StealthCoder is the hedge that gets you a clean solution fast.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Button Combination Detector cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass SpaceX's OA.

SpaceX reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Button Combination Detector FAQ

What's the trick in the SpaceX Button Combination Detector?+

Check the condition after every event, not at the end. The combination only has to exist for one moment. Example 1 returns true even though A is released afterward. Use a set of pressed buttons and test after each update.

How hard is this problem really?+

Easy. It's a single pass with a hash set. The difficulty is in reading the spec carefully: no-op presses, no-op releases, extra buttons allowed, and case-sensitive labels. Most failures come from missing the check-after-each-event rule, not from the algorithm.

Do I need to optimize for 100,000 events?+

Not much. A set gives O(1) add and remove. Rechecking up to 100 required buttons per event is about 10 million operations, which is fine. If you want it tighter, keep a count of required buttons currently down and update it only on relevant events.

What edge cases should I test?+

Test a duplicate down, an up for a button never pressed, and a combination that happens then breaks. Also test case sensitivity, so a and A are different buttons. Add a case where a required button is never pressed, like Example 3, which must return false.

How do I prepare for this in 48 hours?+

Practice event-stream simulations with a set or map: parse, update state, check a condition each step. Write this one from scratch twice. Focus on string splitting at the colon and on checking state at the right moment. That covers most of what this OA tests.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with SpaceX.

OA at SpaceX?
Invisible during screen share
Get it