161. Figurines for the Line
Hard
At an activity, children stand in a line, and each child has a recorded score in notas. You must hand out figurines according to these rules:
- Every child receives at least one figurine.
- If a child has a higher score than a child immediately next to them, they must receive more figurines than that neighbor.
Return the minimum total number of figurines that satisfies all the rules.
Example 1
Input: notas = [1, 0, 2]
Output: 5
Explanation: The minimum quantities are [2, 1, 2].
Example 2
Input: notas = [1, 2, 2]
Output: 4
Explanation: The last child does not need more than the middle child because their scores are equal.
Example 3
Input: notas = [4, 3, 2, 1]
Output: 10
Explanation: The minimum quantities form a decreasing sequence from 4 to 1.
Constraints
- 1 <= notas.length <= 10^5
- -10^9 <= notas[i] <= 10^9
GreedyArrays
Saved in this browser
Caso 1
notas =
[1,0,2]
Expected =
5
Caso 2
notas =
[1,2,2]
Expected =
4
Caso 3
notas =
[4,3,2,1]
Expected =
10
Run checks these 3 cases. Submit runs all 12, including hidden ones.