Fewest Coins for the Team
Workers stand in a line, and ratings[i] is the rating of worker i. Hand out coins so that every worker gets at least 1, and a worker with a higher rating than a worker right next to them gets more coins than that worker. Return the fewest coins that does it.
Example 1
ratings [1,0,2]
returns 5
Coins 2, 1, 2: both ends beat the middle worker.
Example 2
ratings [1,2,2]
returns 4
Coins 1, 2, 1: the last worker ties with the middle one, so 1 is enough.
Constraints
1 <= len(ratings) <= 1000 <= ratings[i] <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.