We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
`
function countingValleys(steps: number, path: string): number {
let level = 0;
let ans = 0;
for (let p of path) {
if (p === 'D') {
level --;
} else if (p === 'U') {
level ++;
}
if (level === 0 && p === 'U') {
ans ++;
}
}
return ans;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Counting Valleys
You are viewing a single comment's thread. Return to all comments →
` function countingValleys(steps: number, path: string): number {
}