Jumping on the Clouds: Revisited

Sort by

recency

|

1178 Discussions

|

  • + 0 comments

    cvxv

  • + 0 comments

    Here is my Python solution! We use a while loop to continually jump k steps forward and subtract the correct amount from the energy.

    def jumpingOnClouds(c, k):
        n = len(c)
        e = 100
        index = 0
        while True:
            index = (index + k) % n
            e -= 1
            if c[index] == 1:
                e -= 2
            if index == 0:
                return e
    
  • + 0 comments

    Here is my C# solution The do while loop help in continueing the traversal until the initial point is reached and making the initial jump.

        static int jumpingOnClouds(int[] c, int k) 
        {
            int e =100;
            int n = c.Count();
            int i =0;
            do{
                i = (i+k)%n;
                e--;
                if(c[i]==1)
                    e-=2;     
            }while(i!=0);
            return e;
        }
    
  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/retgbr5jSsg

    int jumpingOnClouds(vector<int> c, int k) {
        int position = 0, energie = 100;
        do{
            position = (position + k) % c.size();
            energie -= 1 + c[position] * 2;
        }while(position != 0);
        return energie;
    }
    
  • + 0 comments
        java 8
    
        int e = 100;
        for (int i = 1; i <= c.length; i++) {
            int jump = (k * i) % c.length;
    
            if (jump == 0 && c[jump] == 1) {
                e = e - 3;
                break;
            }
            if (jump == 0) {
                e = e - 1;
                break;
    
            } else if (c[jump] == 1) {
                e = e - 3;
    
            } else {
                e = e - 1;
            }
    
        }
        return e;