You are given an integer array nums. You have an integer array arr of the same length with all values set to 0 initially. You also have the following
modify function:
You want to use the modify function to convert arr to nums using the minimum number of calls.
Return the minimum number of function calls to makenumsfromarr.
The test cases are generated so that the answer fits in a 32-bit signed integer.
Input: nums =[1,5]Output: 5Explanation: Increment by 1(second element):[0,0] to get [0,1](1 operation).Double all the elements:[0,1]->[0,2]->[0,4](2 operations).Increment by 1(both elements)[0,4]->[1,4]->**[1,5]**(2 operations).Total of operations:1+2+2=5.
Input: nums =[2,2]Output: 3Explanation: Increment by 1(both elements)[0,0]->[0,1]->[1,1](2 operations).Double all the elements:[1,1]->**[2,2]**(1 operation).Total of operations:2+1=3.
To reach nums from zeros, we need to increment each bit individually and double all elements together. The minimum number of operations is the sum of all set bits (increments) plus the maximum number of doublings needed for any element.