Last active
May 5, 2020 22:56
-
-
Save rakibulalam/7d6be601c77e8eedf9c1d041ab4d2aac to your computer and use it in GitHub Desktop.
Counting Valleys Hacker Rank
This file contains hidden or 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
| 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