HARDasked at 15 companies

Candy

A hard-tier problem at 47% community acceptance, tagged with Array, Greedy. Reported in interviews at Komprise and 14 others.

Founder's read

Candy is a hard array problem that looks deceptively simple: distribute candy to children based on ratings, ensuring each child gets at least one piece and any child with a higher rating than their neighbor gets more candy. Amazon, Mastercard, Tencent, and Flipkart all ask this one. The naive greedy approach fails because you can't solve it in a single pass. You need to think in two directions. About 47% of candidates who attempt it pass, which means the other half miss the core insight or botch the implementation. If this problem hits your live assessment and you blank on the two-pass strategy, StealthCoder solves it invisibly in seconds.

Companies asking
15
Difficulty
HARD
Acceptance
47%

Companies that ask "Candy"

If this hits your live OA

Candy 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 a senior engineer who knows the OA is theater. This is the script.

Get StealthCoder
What this means

The trap is trying to satisfy both neighbors in one left-to-right sweep. You can't. The correct approach runs two passes: first left-to-right ensuring higher ratings than left neighbors get more candy, then right-to-left ensuring higher ratings than right neighbors get more candy. On each pass you only increase candy counts, never decrease. After two passes, all constraints are met. Most failures happen because candidates either attempt a one-pass greedy solution, underestimate the two-pass logic, or mess up the comparison logic in the second pass. The array and greedy topics are both core here. If you haven't drilled this exact pattern before, StealthCoder is your hedge when the OA timer starts.

Pattern tags

The honest play

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

Candy 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 a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Candy interview FAQ

Why doesn't a single left-to-right pass work?+

A one-pass approach can satisfy ratings vs left neighbors, but it violates constraints on the right side. Imagine a sequence like 1, 3, 2. Left-to-right gives candies 1, 2, 1. But the rightmost child has rating 2 (higher than 1) so needs more than 1 candy. You must revisit from the right.

Is Candy still asked at FAANG?+

Yes. Amazon, Tencent, Flipkart, and Mastercard specifically report asking it. It's in the hard bucket and tests whether you understand two-pass greedy logic, not just brute-force optimization. This is a real OA problem.

What's the core trick?+

Two passes, each only increasing candy counts. First pass enforces left-to-right order. Second pass enforces right-to-left. At each position, take the max of what you already assigned and what the current constraint demands. The second pass doesn't undo the first, it refines it.

How does this differ from other greedy array problems?+

Most greedy array problems solve left-to-right or iterate once. Candy forces you to recognize that some constraints live in opposite directions and you need multiple passes to satisfy both. That's the conceptual jump most candidates miss.

What's the acceptance rate and does that mean it's harder than other hard problems?+

47% acceptance is middling for a hard problem. It's not the hardest, but the two-pass insight isn't obvious without seeing the pattern before. If you've drilled two-pass greedy problems, you're likely in the passing group.

Want the actual problem statement? View "Candy" 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.