Picking Numbers
Question :-
https://www.hackerrank.com/challenges/picking-numbers/problem
Solution in C language :-
#include<stdio.h>
int main(){
int n;
scanf("%d",&n);
int a[n],i,j;
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
int t=0;
for(i=0;i<n;i++){
int c=0;
for(j=0;j<n;j++){
if(a[i]==a[j] || a[i]==a[j]+1){
c++;
}
}
if(c>t)
t=c;
}
printf("%d",t);
return 0;
}
Comments
Post a Comment