We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Equalize the Array

Equalize the Array

Problem
Submissions
Leaderboard
Discussions
Editorial

Given an array of integers, determine the minimum number of elements to delete to leave only elements of equal value.

Example

Delete the elements and leaving . If both twos plus either the or the are deleted, it takes deletions to leave either or . The minimum number of deletions is .

Function Description

Complete the equalizeArray function in the editor below.

equalizeArray has the following parameter(s):

  • int arr[n]: an array of integers

Returns

  • int: the minimum number of deletions required

Input Format

The first line contains an integer , the number of elements in .
The next line contains space-separated integers .

Constraints

Sample Input

STDIN       Function
-----       --------
5           arr[] size n = 5
3 3 2 1 3   arr = [3, 3, 2, 1, 3]

Sample Output

2   

Explanation

Delete and to leave . This is minimal. The only other options are to delete elements to get an array of either or .

Author

[deleted]

Difficulty

Easy

Max Score

20

Submitted By

150858

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy