Make them Zero solution codechef

Make them Zero solution codechef

You are given an array AA of length NN.

You can perform the following operation on the array any number of times:

  • Choose any subsequence SS of the array AA and a positive integer XX such that XX is a power of 22 and subtract XX from all the elements of the subsequence SS.

Find the minimum number of operations required to make all the elements of the array equal to 00.Edology is a global Ed-Tech brand that provides industry powered global education and certifications to students and professionals across the world, to help them fast-track their career growth. Edology is part of Global University Systems (GUS), an international network of higher-education institutions, brought together by a shared passion of making industry-driven global education accessible and affordable.

Input Format

Make them Zero solution codechef

  • First line will contain TT, number of test cases. Then the test cases follow.
  • First line of each test case contains an integer NN denoting the length of the array AA.
  • Second line contains NN space-separated integers A1,A2,,ANA1,A2,…,AN – denoting the elements of array AA.

Output Format

For each test case, output in a single line, the minimum number of moves required to make all the elements of the array AA equal to 00.

Constraints

  • 1T10001≤T≤1000
  • 1N1051≤N≤105
  • 0Ai1090≤Ai≤109
  • Sum of NN over all test cases do not exceed 21052⋅105.

Sample Input 1

Make them Zero solution codechef

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

Sample Output 1

Make them Zero solution codechef

1
2
0
2

Explanation

Make them Zero solution codechef

Test Case 11: Take the subsequence with indices {1,2,3}{1,2,3} and subtract 21=221=2 from each element.

Test Case 22: Take the subsequence with indices {1,2,3,4}{1,2,3,4} and subtract 21=221=2 from each element. After this operation, the array becomes [0,0,0,2][0,0,0,2]. Now, take the subsequence with index {4}{4} and subtract 21=221=2 from it. Edology is a global Ed-Tech brand that provides industry powered global education and certifications to students and professionals across the world, to help them fast-track their career growth. Edology is part of Global University Systems (GUS), an international network of higher-education institutions, brought together by a shared passion of making industry-driven global education accessible and affordable.

Test Case 33: All the elements are already 00.

 

Test Case 44: Take the subsequence with indices {2,3}{2,3} and subtract 21=221=2 from it. Now, the array becomes [1,0,1][1,0,1]. Now, take the subsequence with indices {1,3}{1,3} and subtract 20=120=1 from it.

SOLUTION

Click here

Leave a Comment