LearnPy Hub
← Arena
EasyRating 1000

Counting Valleys

A hike starts and ends at sea level. Each step is U (up) or D (down). A valley is a stretch below sea level, from a step down off sea level to the step back up to it. Count the valleys.

Input

A string of U and D.

Output

One integer.

Sample 1

Input
UDDDUDUU
Output
1

Sample 2

Input
DDUUDDUDUUUD
Output
2
solution.py
Output appears here
Counting Valleys · Python Arena problem · LearnPy Hub