Commonly asked Data Structures and Algorithms Problems by big tech and different solution approaches with code in Java and C

Powered by Blogger.

Tuesday, November 22, 2016

Equalize the Array HackerRank in c


#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

Stats