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
function countingValleys(n, s) { | |
let seaLevel = 0; | |
let currLevel = 0; | |
let valleys = 0; | |
s = s.split(''); | |
for (let i = 0; i < s.length; i++) { | |
//update the current level | |
if (s[i] === 'U') { | |
currLevel += 1; | |
if (currLevel == 0) { | |
valleys += 1; | |
} | |
} else { | |
currLevel -= 1; | |
} | |
} | |
return valleys; | |
} | |
function jumpingOnClouds(c) { | |
let jumps = 0 | |
let i = 0 | |
while ( i < c.length) { | |
if (c[i+2] === 0) i += 2 | |
else i += 1 | |
if (i !== c.length) jumps++ | |
// This one makes you really understand what is happening | |
console.log({jumps, i}) | |
} | |
return jumps | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment