# Equal Elements CodeChef Solution

### We Are Discuss About CODECHEF SOLUTION

Equal Elements CodeChef Solution

## Problem

You are given an arrayÂ ďż˝Â of sizeÂ ďż˝. In one operation, you can do the following:

• Select indicesÂ ďż˝Â andÂ ďż˝Â (ďż˝â‰ ďż˝)Â and setÂ ďż˝ďż˝=ďż˝ďż˝.

Find theÂ minimumÂ number of operations required to make all elements of the arrayÂ equal.

### Input Format

• The first line of input will contain a single integerÂ ďż˝, denoting the number of test cases.
• Each test case consists of multiple lines of input.
• The first line of each test case contains an integerÂ ďż˝Â â€” the size of the array.
• The next line containsÂ ďż˝Â space-separated integers, denoting the arrayÂ ďż˝.

### Output Format

For each test case, output on a new line, theÂ minimumÂ number of operations required to make all elements of the arrayÂ equal.

### Constraints

• 1â‰¤ďż˝â‰¤1000
• 1â‰¤ďż˝â‰¤2â‹…105
• 1â‰¤ďż˝ďż˝â‰¤ďż˝
• The sum ofÂ ďż˝Â over all test cases won’t exceedÂ 2â‹…105.

### Sample 1:

Input

Output

3
3
1 2 3
4
2 2 3 1
4
3 1 2 4

2
2
3


### Explanation:

Test caseÂ 1:Â The minimum number of operations required to make all elements of the array equal isÂ 2. A possible sequence of operations is:

• Select indicesÂ 1Â andÂ 2Â and setÂ ďż˝1=ďż˝2=2.
• Select indicesÂ 3Â andÂ 2Â and setÂ ďż˝3=ďż˝2=2.

Thus, the final array isÂ [2,2,2].

Test caseÂ 2:Â The minimum number of operations required to make all elements of the array equal isÂ 2. A possible sequence of operations is:

• Select indicesÂ 3Â andÂ 2Â and setÂ ďż˝3=ďż˝2=2.
• Select indicesÂ 4Â andÂ 3Â and setÂ ďż˝4=ďż˝3=2.

Thus, the final array isÂ [2,2,2,2].

Test caseÂ 3:Â The minimum number of operations required to make all elements of the array equal isÂ 3. A possible sequence of operations is:

• Select indicesÂ 2Â andÂ 1Â and setÂ ďż˝2=ďż˝1=3.
• Select indicesÂ 3Â andÂ 1Â and setÂ ďż˝3=ďż˝1=3.
• Select indicesÂ 4Â andÂ 1Â and setÂ ďż˝4=ďż˝1=3.

Thus, the final array isÂ [3,3,3,3].

## SOLUTION

Yhaa You have done it but next? if YOU Want to Get Others Please Visit HereÂ ScishowEngineerÂ Â  ThenÂ Follow US HEREÂ andÂ Join Telegram.