Skip to content
StackDecode
GreedyExplained

Candy Distribution

Two passes make each child get more than a lower-rated neighbour.

Time

O(n)

Extra space

O(n)

Use it for

Local-constraint assignment.

An animated walkthrough for this algorithm isn’t built yet. The summary above explains the idea; see the related animated algorithms below to practise the same technique.