You are viewing a single comment's thread. Return to all comments →
def counting_valleys(steps, path): count = level = 0 in_valley = False for i in range(steps): level += 1 if path[i] == "U" else -1 if level == -1 and path[i] == "D" and not in_valley: count += 1 in_valley = True if level == 0 and path[i] == "U" and in_valley: in_valley = False return count
Seems like cookies are disabled on this browser, please enable them to open this website
Counting Valleys
You are viewing a single comment's thread. Return to all comments →