As reported: Dropbox SWE intern online assessment on CodeSignal (Feb 2026): 4 questions in 70 minutes; this was the algorithm question.
This is LeetCode 135 — Candy. Our write-up: /candy.
n children stand in a line; child i has rating ratings[i]. Give each child candies so that:
- every child gets at least one candy, and
- a child with a higher rating than a neighbor gets more candies than that neighbor.
Return the minimum total number of candies.
Example 1
ratings = [1,0,2]
Output: 5 (2, 1, 2)
Example 2
ratings = [1,2,2]
Output: 4 (1, 2, 1 — equal neighbors need nothing)
Constraints: 1 ≤ n ≤ 2·10^4; 0 ≤ ratings[i] ≤ 2·10^4.
Code runner format: one JSON value per line: ratings. Implement candy(ratings).