Sort by

recency

|

3287 Discussions

|

  • + 0 comments

    Guys, this is a math problem. The solution lies in understanding that it's just walks and jumps. The solution can be defined as: floor((n+walks)/2), where n is the total number of clouds. A walk in this case represents a forced walk (when there is an even number of clouds between two consecutive thunderclouds)

    My solution in python:

    def jumpingOnClouds(c):
        # Write your code here
        n = len(c)
        walks = 0
        last_thunderhead = -1
        for i in range(n):
            if c[i]:
                if (i - last_thunderhead)%2:
                    walks += 1
                last_thunderhead = i
        return math.floor((n + walks)/2)
    
  • + 0 comments

    C++

    int jumpingOnClouds(vector<int> &c) {
        int cnt = 0;
    
        for (int j = 0; j < c.size() - 1; j = j + 2) {
            if (c[j + 2] == 1) {
                j--;
                cnt++;
            } else { cnt++; }
        }
    
        return cnt;
    }
    
  • + 0 comments
    function jumpingOnClouds(c: number[]): number {
        let jumps = 0
        for(let i=0; i < c.length - 1; i++){
            const nextDoubleCloud = c[i + 2]
            if(nextDoubleCloud == 0) {
                i++
            }
            jumps++
        }
        return jumps
    }
    
  • + 0 comments

    Jumping on the Clouds sounds like such a fun and creative concept! Whether it's about tackling challenges or dreaming big, it's a reminder to aim high. Just like in life, though, it’s always smart to stay grounded while pursuing those big dreams. What’s the story behind this idea?

  • + 0 comments

    def jumpingOnClouds(c): # Write your code here cnt=0 i=0 while i+2