this is an algo peoblem from hacker rank
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
this is an algo peoblem from hacker rank https://www.hackerrank.com/challenges/counting-valleys/problem?isFullScreen=true | |
*/ | |
function countingValleys(steps, path) { | |
let count = 0; | |
let level = 0; | |
path.split("").forEach(unit => { | |
if(unit === "D") { | |
level-- | |
} else { | |
level++ | |
}; | |
if(level == 0 && unit === "U") count++; | |
}); | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment