EASYasked at 1 company

Distribute Candies

A easy-tier problem at 70% community acceptance, tagged with Array, Hash Table. Reported in interviews at LiveRamp and 0 others.

Founder's read

Distribute Candies is an Array problem that appears deceptively simple but catches people on the logic. LiveRamp has asked it. The acceptance rate sits around 70%, which sounds high until you realize most failures come from off-by-one bugs or misunderstanding the constraint that each child must get at least one candy. The trick isn't complex, but getting it right under timed pressure requires knowing the pattern. If you hit this on your OA and freeze, StealthCoder surfaces a working solution in seconds, invisible to the proctor.

Companies asking
1
Difficulty
EASY
Acceptance
70%

Companies that ask "Distribute Candies"

If this hits your live OA

Distribute Candies 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 Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.

Get StealthCoder
What this means

The core pattern: you need to satisfy two constraints simultaneously, and a greedy single-pass won't work. Most candidates try left-to-right only and miss children on the right who have higher ratings. The solution requires two passes, one left-to-right and one right-to-left, to propagate the constraint in both directions. Common mistake is initializing the candy array wrong or not handling the update logic correctly on the second pass. This is where Array and Hash Table topics intersect, though Hash Table is often used for rating lookups or validation rather than the main algorithm. When you nail the two-pass greedy approach, the problem becomes trivial. If you haven't drilled this pattern, StealthCoder hedges the live assessment by showing the exact two-pass structure.

Pattern tags

The honest play

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

Distribute Candies recycles across companies for a reason. It's easy-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 Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Distribute Candies interview FAQ

Why does a single left-to-right pass fail?+

A single pass only compares each child with their left neighbor. If a child has a higher rating than their right neighbor, you won't catch it until a second pass. Without the second pass, you'll assign fewer candies than required. Two passes, one in each direction, enforce the constraint globally.

Is this problem still asked at tech companies?+

Yes. LiveRamp has confirmed it. The acceptance rate is about 70%, but that includes people who stumbled into the two-pass solution or had prior exposure. Cold candidates often fail on logic or off-by-one errors.

What role does the Hash Table topic play?+

Hash Table is useful for caching ratings or validating the input, but it's not central to the algorithm. The core solution is a greedy two-pass Array traversal. Hash Table might help if the problem variant asks for lookups, but expect the main solution to be Array-focused.

What's the minimum number of candies I need to distribute?+

At least n, where n is the number of children. Each child must get at least one candy. The trick is determining how many extra candies to add based on rating differences. Most solutions end up distributing significantly more than n.

How do I avoid off-by-one errors on the second pass?+

Be explicit about your loop bounds and update logic. On the backward pass, compare the current child's rating with the next child's rating, not the previous. Update the current candy count only if the constraint is violated. Write out a small example and trace through it by hand before coding.

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