Problem Brief
Get Minimum Operations
OA
Starting from 0, add 1, then multiply by 2 three times. It takes a minimum of 4 operations to get to 8, so store 4 in index 0 of the return array.
Function Description
Complete the function getMinOperations in the editor with the following parameter(s):
kValues[n]: the values to match
Returns
int[n]: answers to a list of queries in the given order
Constraints
- 1 β€ n β€ 10^4
- 0 β€ kValues β€ 10^16
Deepest thanks to an old friend for their kind help, with sincere, boundless gratitude. π·
1Example 1
Input
kValues = [5, 3]
Output
[4, 3]
Explanation
0. To get from 0 to
kValues[0] = 5, ADD_1 β MULTIPLY_2 β MULTIPLY_2 β ADD_1 to get 0 + 1 β 1 Γ 2 β 2 Γ 2 β 4 + 1 = 5. Because it took four operations, store 4 in index 0 of the return array.
1. To get from 0 to kValues[1] = 3, ADD_1 β MULTIPLY_2 β ADD_1 to get 0 + 1 β 1 Γ 2 β 2 + 1 = 3. Because it took three operations, store 3 in index 1 of the return array.