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
  5. Discussions

Jumping on the Clouds

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • billones_kenllo1
    3 months ago+ 0 comments

    Java Simpler Solution

    public static int jumpingOnClouds(List<Integer> c) {
        int jumps = 0;
        jumps += c.size() == 2 ? 1 : 0;
        for(int i = 2; i < c.size(); i+=2){
            if(c.get(i) == 1){
                i -= 1;
            }
            jumps++;
            i -= i + 2 >= c.size() ? 1 : 0;
        }
        return jumps;
    }
    

    JavaScript Simpler Solution

    function jumpingOnClouds(c) {
        var jumps = 0
        jumps += 2 == c.length ? 1 : 0
        for(var i = 2; i < c.length; i+=2){
            if(c[i] == 1){
                i -= 1
            }
            jumps++
            i -= i + 2 >= c.length ? 1 : 0
        }
        return jumps
    }
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy