Answers for "valley and mountains hackerrank solution"

0

Counting Valleys

# HackerRank.com "Counting Valleys" problem
def countingValleys(n, s):
    total_valley = 0
    location = 0

    for i in range(n):

        if s[i] == 'D':
            if location == 0:
                total_valley = total_valley + 1
            location = location - 1
			continue
        elif s[i] == 'U':
            location = location + 1

    return total_valley
Posted by: Guest on June-29-2020

Code answers related to "valley and mountains hackerrank solution"

Python Answers by Framework

Browse Popular Code Answers by Language