We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Jumping on the Clouds: Revisited
  5. Discussions

Jumping on the Clouds: Revisited

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 1088 Discussions, By:

recency

Please Login in order to post a comment

  • linhvo2795
    3 days ago+ 0 comments

    java

    public class Solution {
    
        public static void main(String []args)
        {
            Scanner scan = new Scanner(System.in);
            int n = scan.nextInt();
            int step=0;
            int e=100;
            int k= scan.nextInt();
            int []a = new int[n+1];
            for(int i=0;i<n;i++)
            {
                a[i]= scan.nextInt();
            }
            
            while(true)
            {
                step +=k;
                step%=n;
                  e--;
                   if(a[step]==1)
                    e-=2;
                    if(step==0)
                   break;
                
            }
            System.out.print(e);
        }
    }
    
    0|
    Permalink
  • flavio_gpinheiro
    5 days ago+ 0 comments

    My JavaScript Solution

    function jumpingOnClouds(c, k) {
        let i = 0;
        let energy = 100;
        do {
            if (c[i] == 1) energy -= 2;
            i = (i + k) % c.length;
            energy--;
        } while (i !== 0);
    
        return energy;
    }
    
    0|
    Permalink
  • rishabhjainiitd
    6 days ago+ 0 comments

    What if its all energy is drained?

    0|
    Permalink
  • thanhtuanle939
    2 weeks ago+ 0 comments
    static int jumpingOnClouds(int[] c, int k) {
            int i=0;
            int n = c.length;
            int energy = 100;
            do {
                    if (c[i] == 1) {
                            energy -= 2;
                    }
    
                    i = (i + k) % n;
                    energy--;
            } while (i != 0);
    
            return energy;
    }
    
    0|
    Permalink
  • g_p_hector_alej1
    2 weeks ago+ 0 comments

    in node js****

    function jumpingOnClouds(c, k) { let energy = 100 const n = c.length let i = 0

    do {
        if (c[i] === 1) {
            energy -= 2
        }
    
        i = (i + k) % n
        energy--
    } while (i !== 0)
    
    return energy
    

    }

    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy