• + 0 comments
      int countingValleys(int steps, string path) {
                int down=0,in_valleys=0,up=0,count=0 ;
                for(int i=0;i<path.size();i++){
                    if(path[i]=='U') up++;
                    if(path[i]=='D') down++;
                    if(down-up>0&&in_valleys==0){
                        count++;
                        in_valleys++;
                    }
                    if(down-up==0&&in_valleys!=0){
                        in_valleys =0;
                    }
                }
                return count;
            }