Skip to content

Instantly share code, notes, and snippets.

@rachidelaid
Created May 10, 2022 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rachidelaid/81e78af2be76d9e8c1d2a78e39807934 to your computer and use it in GitHub Desktop.
Save rachidelaid/81e78af2be76d9e8c1d2a78e39807934 to your computer and use it in GitHub Desktop.
this is an algo peoblem from hacker rank
/*
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