EQUALIZE THE ARRAY
Target CodeVita (Problem 11)
Problem Statement
Given an array of integers, determine
the minimum number of elements to
delete to leave only elements of equal
value.
Explanation With Examples
Suppose, an array with five elements is given as:
1, 3, 3, 2, 2, 2
Case 1: After 5 deletions (3, 3, 2, 2, 2), output
array will contain 1
Case 2: After 4 deletions (1, 2, 2, 2), output array
will contain 3, 3
Case 3: After 3 deletions (1, 3, 3), output array
will contain 2, 2, 2
Minimum Deletions are 3. So, the output will be 3.
Cont…
Suppose, an array with four elements is given as:
1, 2, 2, 3
Case 1: After 3 deletions (2, 2, 3), output array will
contain 1
Case 2: After 2 deletions (1, 3), output array will contain
2, 2
Case 3: After 3 deletions (1, 2, 2), output array will
contain 3
Minimum Deletions are 2. So, the output will be 2.
Imposed Constraints
1 ≤ n ≤ 100
(where, n is the number of elements in array)
1 ≤ arr[i] ≤ 100
(Means array can contain integer value maximum upto 100)
Inputs to the Problem
The first line contains an
integer, n, the size of arr.
The second line describes
array arr as n space-separated
integers.
4 Total number of elements
1223 Array contains integer values
Output of the Problem
int: minimum number of
deletions required to
equalize the array
Output: 2
Logic
Will be described on
board