You are viewing a single comment's thread. Return to all comments →
Python Solution: def countingValleys(steps, path): sea_level = 0 return sum(1 for i in range(steps) if (sea_level := sea_level + 1 if path[i] == 'U' else sea_level - 1) == 0 and path[i] == 'U')
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 →
Python Solution: def countingValleys(steps, path): sea_level = 0 return sum(1 for i in range(steps) if (sea_level := sea_level + 1 if path[i] == 'U' else sea_level - 1) == 0 and path[i] == 'U')