Quant Memo
Coding/●●●●

Candy on the trading floor

Traders sit in a row, each with a performance rating. You give each at least one treat, and any trader rated higher than an immediate neighbor must get strictly more treats than that neighbor. Minimize the total handed out.

ratings = [1, 0, 2]  ->  5      # treats [2, 1, 2]
ratings = [1, 2, 2]  ->  4      # treats [1, 2, 1]

Return the minimum total number of treats.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions