[Solution] Add to Subsequence CodeChef Solution
Problem
Chef has an array of length .
In one operation, Chef can choose any subsequence of the array and any integer and then add to all the elements of the chosen subsequence.
Determine the minimum number of operations required to make all the elements of the array distinct.
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 a single integer — the length of Array .
- Next line contains space-separated integers - denoting the array .
Output Format
For each test case, output the minimum number of operations required to make all the elements distinct.
Explanation:
Test case :
- Operation : Choose the subsequence and add to the elements. The array becomes .
- Operation : Choose the subsequence and add to the elements. The array becomes .
Thus, we require, minimum operations to make all the elements distinct.
Test case :
- Operation : Choose the subsequence and add to the elements. The array becomes .
- Operation : Choose the subsequence and add to the elements. The array becomes .
Thus, we require, minimum operations to make all the elements distinct.
Test case :
- Operation : Choose the subsequence and add to the elements. The array becomes .
Thus, we require, minimum operation to make all the elements distinct.
Test case : All the elements are distinct. We need zero operations.
No comments:
Post a Comment