Z40
Candy Distribution
Problem Statement & Objective
There are n children standing in a line. Each child has a rating value. Distribute the minimum number of candies such that higher rated children get more than their neighbors.
Function Signature (Python)
candy_distribution(scores: list[int]) -> intInput & Output Contract
Output Rule:Minimum şeker sayısı.
System Constraints
1 <= puanlar.length <= 2 * 10^4
0 <= puanlar[i] <= 2 * 10^4Example Execution Walkthrough
puanlar = [1, 0, 2] -> şekerler: [2, 1, 2] -> toplam: 5
puanlar = [1, 2, 2] -> şekerler: [1, 2, 1] -> toplam: 4Example Test Scenarios (3)
Example 1
Input:
[[1,0,2]]Expected Output:
5Example 2: Eşit Puan
Input:
[[1,2,2]]Expected Output:
4Example 3: Tek Çocuk
Input:
[[1]]Expected Output:
1