Sort by

recency

|

4155 Discussions

|

  • + 0 comments
    int countingValleys(int steps, string path) {
        int path_counter = 0, valeys = 0;
        bool topo = true;
        
        for(char c : path){
            
            if(c=='U'){
                path_counter++;
                
                if(path_counter>=0){
                    topo = true;
                }
            }
            
            if(c=='D'){
                path_counter--;
                
                if(path_counter<0 && topo){
                    valeys++;
                    topo = false;
                }
                
            }
        }
        
        return valeys;
    }
    
  • + 1 comment

    Can you help to integrate this algirithem script with my drive zone game page? I want to use it on my Worldpress website.

  • + 0 comments

    kotlin

    fun countingValleys(steps: Int, path: String): Int {
        // Write your code here
        var alt = 0
        var valleys = 0
        for(step in path){
            if(step.equals('U')){
                if(alt == -1)
                    valleys++
                alt++
            }
            else if(step.equals('D'))
                alt--
            
        }
        return valleys
    }
    
  • + 0 comments
            int seaLevel = 0;
            int valleyCount = 0;
    
            for (char step : path.toCharArray()) {
    
                    if (step == 'U') {
    
                            seaLevel++;
    
                            if (seaLevel == 0) {
    
                                    valleyCount++;
                            }
                    } else {
    
                            seaLevel--;
                    }
            }
    
            return valleyCount;
    
  • + 0 comments

    java 8

                int l = 0;
        int count = 0;
        boolean check = false;
    
        for(char c : path.toCharArray()){
            if(c == 'U'){
                l++;
                if(l > 0){
                    check =true;
                } else {
                    check = false;
                }
            } else {
                l--;
            }
            if(l == 0 && !check){
                count++;
            }