Equalize the Array HackerRank solution in c
Available at https://www.hackerrank.com/challenges/equality-in-a-array
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
int s,count=1;
scanf("%d",&s);
int *arr=malloc(sizeof(int));
for(int i=0;i<s;i++)
scanf("%d",&arr[i]);
for(int i=0;i<s;i++)
{
int temp=1;
for(int j=i+1;j<s;j++)
{
if(arr[i]==-12523)
break;
else if(arr[i]==arr[j])
{
temp++;
arr[j]=-12523;
}
if(temp>count)
count=temp;
}
//printf("%d\t",count);
}
printf("%d",s-count);
return 0;
}
0 Comments:
Post a Comment