Jumping On The Clouds

 Question :-

https://www.hackerrank.com/challenges/jumping-on-the-clouds/problem

Solution in C language :-

#include<stdio.h>
main()
{
    int n,i,sum=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    for(i=0;i<n;)
    {
        if(a[i+1]==0&&a[i+2]==1)
        {
            i=i+1;
            sum++;
        }
        else
        {
            sum++;
            i=i+2;
        } 
        if(i==n-1)
        sum--;  
    }
    printf("%d",sum);
}

Comments

Popular posts from this blog

Sherlock and Squares

Cut The Sticks

Home