HARDasked at 2 companies

Maximum Candies You Can Get from Boxes

A hard-tier problem at 69% community acceptance, tagged with Array, Breadth-First Search, Graph. Reported in interviews at Airbnb and 1 others.

Founder's read

You're faced with nested box-opening logic where each box unlocks others, and you need to count the maximum candies reachable. Airbnb and Lyft have asked this. The trap is treating it as a simple traversal problem when it's actually a constraint-satisfaction graph where you must track which keys you've found to unlock future boxes. Miss the dependency ordering and you'll miss reachable candies. If this problem hits your live OA and the BFS pattern doesn't click, StealthCoder solves it invisibly in seconds, surfacing a working solution while you stay undetected.

Companies asking
2
Difficulty
HARD
Acceptance
69%

Companies that ask "Maximum Candies You Can Get from Boxes"

If this hits your live OA

Maximum Candies You Can Get from Boxes is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.

Get StealthCoder
What this means

The core trick is recognizing this as a graph exploration problem where boxes are nodes and keys are edges. You can't just DFS or BFS blindly. The algorithm requires tracking three states: boxes you have, keys you've collected, and boxes you've opened. When you encounter a locked box without its key, you must defer opening it. BFS works here because you process boxes level by level, checking at each step whether newly acquired keys unlock boxes you've queued but couldn't open yet. Most candidates initially write a linear scan and miss the cyclical dependency pattern. The actual gotcha is maintaining a queue of unopened boxes and re-checking them when new keys arrive. StealthCoder handles the state management and ordering logic so you don't implement a half-working solution under time pressure.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Maximum Candies You Can Get from Boxes recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximum Candies You Can Get from Boxes interview FAQ

Is this really a hard problem or inflated difficulty?+

The acceptance rate sits at 68.8%, suggesting it's hard but solvable with clear pattern recognition. The difficulty spike comes from managing multiple state variables and deferring box openings until keys arrive, not from complex math.

Why doesn't a simple DFS work?+

DFS processes one path completely before backtracking. Here, you might encounter a locked box and stop, missing that another branch later gives you the key. BFS with deferred opening ensures you exhaust all currently reachable boxes before moving deeper.

What's the relationship between Graph and the other topics?+

Boxes form nodes and keys form directed edges. Breadth-First Search is the traversal method. The Array stores which boxes and keys you have. Together they model the constraint graph.

Do Airbnb and Lyft ask this regularly?+

Both companies appear in reports for this problem, though frequency varies. It tests whether you can model real-world dependency problems as graphs and handle state changes during traversal.

What's the most common mistake candidates make?+

Forgetting to re-check previously encountered locked boxes once new keys arrive. Candidates process boxes once and never revisit them, missing candies behind newly unlocked boxes.

Want the actual problem statement? View "Maximum Candies You Can Get from Boxes" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.