Minimum Operations to Transform

Company: Infosys__..

Difficulty: medium

Problem Statement

Minimum Operations to Transform Problem Description Two operations are available on an integer: ADD_1 : increment the integer by 1. MULTIPLY_2 : multiply the integer by 2. You are given a list of integers kValues . For each kValues[i] , determine the minimum number of operations needed to transform the number 0 into kValues[i] using only those two operations. Report the answer for every element of the list. The function to implement is getMinOperations . Input Format The first line contains an integer n, the size of kValues . The second line contains n space-separated integers, the elements of kValues . Output Format Print one line with n space-separated integers: the minimum number of operations for each element of kValues , in the same order. Constraints 1 <= n <= 2000 0 <= kValues[i] <= 10000000000000000 Examples Example 1 Input: 3 8 5 3 Output: 4 4 3 Explanation: To get 8: 0 -> 1 -> 2 -> 4 -> 8 , that is 1 ADD_1 and 3 MULTIPLY_2, total 4. To get 5: 0 -> 1