Cut The Sticks

 Question :-

https://www.hackerrank.com/challenges/cut-the-sticks/problem

Solution in C language :-

#include<stdio.h>
int main(){

    int n;
    scanf("%d",&n);
    int a[n],i;
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    int temp=a[0],j,t=n,c=0,d=0;
    printf("%d\n",n);
    for(j=0;j<t;j++){
        temp=1000;
        for(i=0;i<n;i++){
            if(a[i]>0){
                if(temp>a[i])
                    temp=a[i];
            }
        }
        for(i=0;i<n;i++){
            a[i]=a[i]-temp;
            if(a[i]>0)
                d++;
            if(a[i]==0)
                c++;
        }
        t=t-c+1;
        c=0;
        if(d>0)
            printf("%d\n",d);
       d=0;
    }


    return 0;
}

Comments

Popular posts from this blog

Sherlock and Squares

Home