Sort by

recency

|

3248 Discussions

|

  • + 0 comments
    function jumpingOnClouds(c) {
      
       
        let counter = 0; // minimal jumps
        
        if (c.length === 3){
            return 1
            
        }
       
            
            for (let i = 0;  i < c.length; i++){
                
                if (c[i] === 0){
                     if (c[i + 2] === 0){
                         counter++
                         i = i +1;
                         
       
                      } else {
                         if (c[i + 1] === 0 ){
                          counter++
                         
                          }
       
                      }
                    
                }
       
              
               
            }
       
        
        
        return counter
    
    }
    
  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/GNof9B-9CN0

    int jumpingOnClouds(vector<int> c) {
        int result = 0, index = 0;
        while(index < c.size() - 1){
            if(c[index + 2] == 1) index++;
            else index+=2;
            result++;
        }
        return result;
    }
    
  • + 0 comments

    Solution for c#

    public static int jumpingOnClouds(List<int> c)
        {
            int jumpCount = 0;
            int zeroCount = 0;
            
            for (int x = 0; x < c.Count; x++) {
               if (c[x] == 0) {
                   zeroCount++;
                   
                   if (x == c.Count -1) {
                        int quotient = (int)(zeroCount / 2);
                        jumpCount = jumpCount + quotient;
                   }
               } else if (c[x] > 0 || x == c.Count -1) {
                   int quotient = (int)(zeroCount / 2) + 1;
                   jumpCount = jumpCount + quotient;
                   
                   zeroCount = 0;
               }
            }
            return jumpCount;
        }
    
  • + 0 comments

    public static int jumpingOnClouds(List c) { //narayan gupta int jumps = 0; int i = 0; while (i < c.size() - 1) { if (i + 2 < c.size() && c.get(i + 2) == 0) { i += 2; // Jump 2 clouds if possible } else { i += 1; // Otherwise, jump 1 cloud } jumps++; // Count each jump } return jumps;
    }

  • + 0 comments

    Solution of Jumping on the Clouds

    def jumpingOnClouds(c):
        jump=0
        i=0
        while(i< len(c)-2):
            
            if(c[i+2] != 0):
                jump+=1
                i+=1
                
            elif(c[i+2] == 0):
                jump+=1
                i+=2
    
        if(i == len(c)-1):
            return jump
        
        else:
            return jump+1