You are viewing a single comment's thread. Return to all comments →
My TypeScript solution:
function countingValleys(steps: number, path: string): number { let currentDepth = 0; let valleys = 0; for (let i = 0; i < steps; i++) { if (path[i] === "D" && currentDepth === 0) valleys ++; currentDepth += path[i] === "U" ? 1 : -1; } return valleys; }
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 →
My TypeScript solution: