Sort by

recency

|

4163 Discussions

|

  • + 0 comments

    Excellent breakdown of the Counting Valleys problem! I worked on something similar back when I was practicing algorithms. Also, for those curious about the Free Fire Advance Server including how to register and access new updates I’ve put together a complete guide you might find helpful. corporate-car-service

  • + 0 comments
    def countingValleys(steps, path):
        level=0
        valley=0
        for i in path:
            if i=="U":
                level+=1
                if level==0:
                    valley+=1
            else:
                level-=1
        return valley
    
  • + 0 comments

    Briefest I can make it in Python

    def countingValleys(steps, path):
        elevation = count = 0
        for i in range(steps):
            elevation += 1 if path[i] == "U" else -1
            if elevation == 0 and path[i] == "U":
                count += 1
        return count
    
  • + 0 comments

    Great explanation of the Counting Valleys problem. I remember solving this when I was learning algorithms. By the way, if anyone is interested in the Free Fire Advance Server and wants to know how to register or get the latest updates, I’ve written a detailed guide here

  • + 0 comments

    ` 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;
    

    }