Sort by

recency

|

4145 Discussions

|

  • + 0 comments

    Great insights on algorithm scripts. It’s interesting how similar logic applies in logistics too. Check out OM Van Lines[ best movers in new jersey](https:// https://omvanlines.com/ ) for real-world use of optimized moving strategies. I want to use it on my WordPress website.

  • + 0 comments
    def countingValleys(steps, path):
        # Write your code here
        
        valleys = 0
        level = 0
        for i in range(steps):
            if path[i] == "U":
                level += 1
                if level == 0:
                    valleys += 1
            else:
                level -= 1
                  
        return valleys
    
  • + 0 comments

    Great explanation of counting valleys here! The logic—tracking altitude changes and recognizing when you're exiting a valley (i.e. going from below sea level back to zero)—is spot on. It’s really helpful to see the condition if (level == 0 && step == 'U') ++valleys; clearly broken down.

    By the way, if anyone’s working on code challenges while planning overseas travel or residency, you might also be juggling documentation like police clearance. For instance, those applying in the Philippines often need a police clearance to show good conduct. Just a friendly heads-up for anyone balancing coding tasks and bureaucracy!

  • + 0 comments

    My solution c++

    int countingValleys(int steps, string path) {
     int stepsCount=0,valley=0;
     for(int i=0; i<steps; i++){
        if(path[i]=='U'){
          stepsCount++;
          if(stepsCount==0) valley++;
        }
        else if(path[i]=='D'){
          stepsCount--;
        }
     }
     return valley;
    }
    
  • + 1 comment
    public static int countingValleys(int steps, String path) {
    // Write your code here
    int ans = 0,level=0;
    for(char c: path.toCharArray()) {
        if(c=='U') level+=1;
        else level-=1;
        if(level==0 && c=='U') ans++;
    }
    return ans;
    

    } `