Last Updated: 23 Jun, 2022

Reduce Array

Easy
Asked in company
Deloitte

Problem statement

You are given an array ‘Arr’ of ‘N’ integers. Your task is to reduce each of the elements to zero. You can perform the following two operations on the array. Select an index ‘i’. If ‘Arr[i]’ is odd then replace it with ‘(Arr[i]-1) / 2’ else replace it with ‘Arr[i] / 2’.

Return the total number of operations required to reduce each element of the array to zero.

Example:

‘N’=5, ‘Arr’ = [2 , 5 , 6 , 3 , 1].
2 -> 1 -> 0
5 -> 2 -> 1 -> 0
6 -> 3 -> 1 -> 0
3 -> 1 -> 0
1 -> 0

Hence total operations will be 11.
Input Format :
First-line contains 'T', denoting the number of Test cases.
Each Test case contains 2 lines.
First-line contains an integer ‘N’.
Second-line contains ‘N’ integers, elements of ‘Arr’.   
Output Format:-
Your task is to return the total number of operations required to reduce the array.      
Note:-
You don’t need to print anything. Just implement the given function.
Constraints :
1<=‘T’<=10
1<=‘N’<=10^5
1<=‘Arr[i]’<=10^9

Time Limit: 1 sec