https://www.hackerrank.com/challenges/picking-numbers/problem
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int a[n],h[100]={0},i;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
h[a[i]]++;
}
long long int max=0;
for(i=0;i<100;i++)
{
if(h[i] > 0 && i<99 && h[i+1] > 0)
{
if(max < h[i]+h[i+1])
max=h[i]+h[i+1];
}
else if(h[i] > 0)
{
if(max < h[i])
max=h[i];
}
}
printf("%d",max);
}
No comments:
Post a Comment