본문 바로가기

hacking sorcerer

Problem: Valley Count in a Number Path

728x90
반응형

Problem: Valley Count in a Number Path

You are given a list of integers that represent steps going up or down on a path.

Rules

The path always starts at height 0.

Each number in the list tells how much the height changes at that step.

Positive → go up   
Negative → go down

A valley is counted when:

You go below height 0, and       
Later return back to height 0.

Your task: Count how many valleys happen in the path.

Input

A list of integers (at least one value).

Output

A single integer: the number of valleys.

e.g.

Example 1

Input: [1, -2, -1, 2]

Explanation (not a hint, just clarity of the sample):
The path goes below 0 and comes back — that is 1 valley.

Output: 1

Example 2

Input: [-1, -1, 2, -3, 3]

Output: 2

728x90
반응형

'hacking sorcerer' 카테고리의 다른 글

Problem: Balance the Boxes  (0) 2025.12.16
really beautiful  (0) 2025.12.10
너무 잘 만들어진 해커들의 놀이터 한국  (0) 2025.12.01
coffee heaven  (0) 2025.11.25
heaven in the tea  (0) 2025.11.24