Sunday, 30 August 2020

Min Max Hacker Earth solution in C

 https://www.hackerearth.com/practice/basic-programming/implementation/basics-of-implementation/practice-problems/algorithm/min-max-3/submissions/


#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int a[n],i,max,min,h[1001]={0},flag=0;
    scanf("%d",&a[0]);
    max=min=a[0];
    h[a[0]]++;
    for(i=1;i<n;i++)
    {
        scanf("%d",&a[i]);
        h[a[i]]++;
        if(max < a[i])
            max=a[i];
        if(min > a[i])
            min=a[i];
    }
for(i=min;i<=max;i++)
        if(h[i] == 0)
        {
            flag=1;
            break;
        }
    if(flag == 1)
        printf("NO");
    else
        printf("YES");
}

No comments:

Post a Comment