Sort by

recency

|

3271 Discussions

|

  • + 0 comments
    public static int jumpingOnClouds(List<Integer> c) {
            int count = 0;
            for (int i = c.size() - 1; i > 0; i--) {
                int p = i - 2;
                int q = i - 1;
                if (p > -1 && c.get(p) != 1) {
                    i = q;
                }
                count++;
            }
            return count;
        }
    
  • + 0 comments

    give me your opinion please i need it

        public static int jumpingOnClouds(List<Integer> c) {
            if (c.isEmpty() || c.size() < 2) return 0;
            if (c.get(c.size() - 1) != 0) return 0;
            int jumpsRequired = 0;
            int i = 0;
            while (i < c.size() - 1) {
                if ((i + 1 < c.size() && c.get(i + 1) == 1) && (i + 2 < c.size() && c.get(i + 2) == 1)) {
                    break;
                }
                int next = i + 1;
                int afterNext = next + 1;
                if (afterNext < c.size() && c.get(afterNext) == 0) {
                    i = afterNext;
                    jumpsRequired++;
                } else if (next < c.size() && c.get(next) == 0) {
                    i = next;
                    jumpsRequired++;
                }
            }
            return jumpsRequired;
        }
    
  • + 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
    public static int jumpingOnClouds(List<Integer> c) {
    // Write your code here
    int count=0;
    int i=0;
    while(i+2<c.size()){
        if(c.get(i+2)==0)
        i+=2;
        else if(c.get(i+1)==0){
            i++;
        }
        count++;
    }
    if(i+1<c.size() && c.get(i+1)==0){
        count++;
    }
    return count;
    

    }

  • + 0 comments

    python implementation

    def jumpingOnClouds(c):
        # Write your code here
        jumps = 0
        i=0
        c_len=len(c)
        while i < c_len - 1:
            j=2
            while j >0:
                if i+j<=c_len-1:
                    if c[i+j]==0:
                        i+=j
                        jumps+=1
                        break
                    else:
                        j-=1
                else:
                    j-=1
        return jumps