Friday, 28 August 2020

Lisa's Workbook Hacker Rank Solution in C

https://www.hackerrank.com/challenges/lisa-workbook/copy-from/176618880 

#include <stdio.h>

int main() 
{
    int n,k; 
    scanf("%d%d", &n,&k);
    int a[n],i,np=0,ans=0,sprn,eprn;
    for(i = 0; i < n; i++)
    {
        scanf("%d",&a[i]);
        sprn=1,eprn=0;
        while(a[i]>0)
        {
            np=np+1;
            if(a[i] > k)
                eprn = sprn+k-1;                     
            else
                eprn=sprn+a[i]-1;    
            if(np>=sprn && np<=eprn)
                ans++;
            a[i]=a[i]-k;
            sprn=eprn+1;
       }
    }
    printf("%d",ans);
}

No comments:

Post a Comment