[Solution] MIN To MAX Solution Codechef

MIN To MAX Solution Codechef

You are given an array  of size .

Let  be the minimum value present in the array initially.
In one operation, you can choose an element �� (1≤�≤�) and an integer  (1≤�≤100), and set ��=�.

Determine the minimum number of operations required to make  the maximum value in the array .

Input Format MIN To MAX Solution Codechef

  • 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 a single integer  – the size of the array.
    • The next line of each test case contains  space-separated integers �1,�2,…,�� – the elements of the array.

Output Format MIN To MAX Solution Codechef

For each test case, output on a new line, the minimum number of operations required to make  the maximum value in the array .

Constraints MIN To MAX Solution Codechef

  • 1≤�≤100
  • 1≤�≤100
  • 1≤��≤100

Sample 1: MIN To MAX Solution Codechef

Input

Output

3
2
1 2
4
2 2 3 4
1
1

 

1
2
0

 

Explanation: MIN To MAX Solution Codechef

Test case 1: The minimum value in the array, , is initially 1. We can use one operation as following:

  • Choose �2 and set it as �=1. Thus, the final array becomes [1,1].

Since all elements of the final array are 1, the maximum value of the array is now 1. It can be shown that this is the minimum number of operations required to do so.

Test case 2: The minimum value in the array, , is initially 2. We can use two operations as following:

  • Choose �4 and set it as �=2. Thus, the array becomes [2,2,3,2].
  • Choose �3 and set it as �=2. Thus, the array becomes [2,2,2,2].

Since all elements of the final array are 2, the maximum value of the array is now 2.

Test case 3: The minimum value in the array, , is initially 1. It is also the maximum value of the array. Hence, no operations are required.

Leave a Comment