← Back

🍬 Fairness Lane

Candy Distribution - Two-Pass Greedy

Kids

-

Phase

-

Current Idx

-

Total Candies

0
🔄 Waiting to start...
Generate ratings and distribute candies fairly!

📖 Candy Distribution

Rule: Higher-rated kids must have more candies than neighbors

Two-Pass Greedy:

1. Left→Right: If rating[i] > rating[i-1], candy[i] = candy[i-1] + 1

2. Right→Left: If rating[i] > rating[i+1], candy[i] = max(candy[i], candy[i+1] + 1)

Time: O(n) | Space: O(n)