Trail Valleys
A hiker follows a trail where each step changes their height relative to sea level. The function counting_valleys receives the number of steps steps and a string path, where U means a step up and D means a step down. A valley starts when the hiker goes below level 0 and ends when they return to sea level. Return the number of valleys walked through.
Примеры
Ввод
8, "UDDDUDUU"Вывод
1Ввод
12, "DDUUDDUDUUUD"Вывод
2Ввод
2, "UD"Вывод
0Нужно реализовать
def counting_valleys(steps: int, path: str) -> int:
Теги
stringsstack
Inicia sesión para ver tu historial de envíos
Iniciar sesiónInicia sesión para usar el AI Mentor
Iniciar sesiónTests12
Visible tests
Prueba oculta 7
Prueba oculta 8
Prueba oculta 9
Prueba oculta 10
Prueba oculta 11
Prueba oculta 12
They run when you press "Submit" — your whole solution is checked against them so you can't hard-code answers for the visible cases.
Focus radio
Paused · SomaFM · Fluid