Skip to content
Programming101
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programmingoneonone

Learn everything about programming

HackerRank Equalize the Array problem solution

YASH PAL, 31 July 2024

In this HackerRank Equalize the Array problem you have Given an array of integers, determine the minimum number of elements to delete to leave only elements of equal value.

HackerRank Equalize the Array problem solution

Topics we are covering

Toggle
  • Problem solution in Python programming.
  • Problem solution in Java Programming.
    • Problem solution in C++ programming.
    • Problem solution in C programming.
    • Problem solution in JavaScript programming.

Problem solution in Python programming.

#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the equalizeArray function below.
def equalizeArray(arr):
    return (len(arr) - arr.count(max(set(arr), key = arr.count)))



if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    n = int(input())

    arr = list(map(int, input().rstrip().split()))

    result = equalizeArray(arr)

    fptr.write(str(result) + 'n')

    fptr.close()

Problem solution in Java Programming.

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int[] occurances = new int[101];
        int n = in.nextInt();
        int maxOccurances = 0;
        //int[] a = new int[n];
        for (int i = 0; i < n; i++)
        {
            int ai = in.nextInt();
            occurances[ai]++;
            if (occurances[ai] > maxOccurances)
            {
                maxOccurances = occurances[ai];
            }
        }
        System.out.println(n - maxOccurances);
    }
}

Problem solution in C++ programming.

#include<bits/stdc++.h>
#define mp make_pair
#define PII pair<int,int>
#define fi first
#define se second
using namespace std;

const int NMAX=105;

int n,a[NMAX],fr[NMAX];

int main()
{
    int i,mx;
   // freopen("date.in","r",stdin);
   // freopen("date.out","w",stdout);
    cin.sync_with_stdio(false);
    cin>>n;mx=0;
    for (i=1;i<=n;i++)
    {
        cin>>a[i];
        fr[a[i]]++;
        mx=max(mx,fr[a[i]]);
    }
    mx=n-mx;
    cout<<mx<<"n";
    return 0;
}

Problem solution in C programming.

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {

    /* Enter your code here. Read input from STDIN. Print output to STDOUT */    
    int N;
    scanf("%d", &N);
    int A[N];
    for(int n = 0; n < N; n++) {
        scanf("%d", &(A[n]));
    }
    int res = 0, count = 0;
    for(int i = 0; i < N; i++) {
        count = 0;
        for(int j = i; j < N; j++) {
            if(A[j] == A[i])
                count++;
        }
        if (count > res)
            res = count;
    }
    printf("%dn", N - res);
    return 0;
}

Problem solution in JavaScript programming.

function processData(input) {
    //Enter your code here
    var arr = input.split('n');
    var len = Number(arr[0]);
    var numbers = arr[1].split(" ").map(Number);
    
    function deleteElement(a, l){
        var dict = {}; 
        var key; 
        var max = 0; 
        for(var i = 0; i < l; i++){
            key = a[i]
            if(key in dict){
                dict[key]++; 
            } else {
                dict[key] = 1; 
            }
        }
        for(var prop in dict){
            if(dict[prop] > max){
                max = dict[prop];
            }
        }
        return l - max; 
    }
    console.log(deleteElement(numbers, len).toString());
} 

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
   processData(_input);
});

Algorithms coding problems solutions

Post navigation

Previous post
Next post
  • Automating Image Format Conversion with Python: A Complete Guide
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes