Z40

Candy Distribution

Staff / Principal Engineer
Target Time: 40 - 50 Minutes
Type: NUMERIC

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]) -> int

Input & Output Contract

Output Rule:Minimum şeker sayısı.

System Constraints

1 <= puanlar.length <= 2 * 10^4
0 <= puanlar[i] <= 2 * 10^4

Example Execution Walkthrough

puanlar = [1, 0, 2] -> şekerler: [2, 1, 2] -> toplam: 5
puanlar = [1, 2, 2] -> şekerler: [1, 2, 1] -> toplam: 4

Example Test Scenarios (3)

Example 1
Input:[[1,0,2]]
Expected Output:5
Example 2: Eşit Puan
Input:[[1,2,2]]
Expected Output:4
Example 3: Tek Çocuk
Input:[[1]]
Expected Output:1
Loading Python Editor...
Input Parameters
[
  [
    1,
    0,
    2
  ]
]
Expected Output
5