Skip to content

Instantly share code, notes, and snippets.

@rakibulalam
Last active May 5, 2020 22:56
Show Gist options
  • Save rakibulalam/7d6be601c77e8eedf9c1d041ab4d2aac to your computer and use it in GitHub Desktop.
Save rakibulalam/7d6be601c77e8eedf9c1d041ab4d2aac to your computer and use it in GitHub Desktop.
Counting Valleys Hacker Rank
function countingValleys(n, s) {
let level=0,vally=0;
for(let i=0; i<=n; i++)
{
if(s[i]==='D')
{
--level
}else if(s[i]==='U'){
if(++level===0) vally++;
}
}
return vally;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment