You are viewing a single comment's thread. Return to all comments →
Typescript:
function countingValleys(steps: number, path: string): number { let valleysCount = 0 let pathSum = 0 let pathMap: { [key: string]: number } = { "D": -1, "U": 1 } for(let character of path) { if(character === "D" && pathSum === 0) valleysCount++ pathSum += pathMap[character] } return valleysCount }
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 →
Typescript: