Given a zero-array (containing only 0's), it is desired to converting it to a certain target array of the same size, and only the following operations are allowed:
Increment : Choose an element from the array and increment it by 1.
Doubling : Double the value of every element on the array
What is the minimum number of operations required to convert a zero-array to the target array shown in the text file ?
Details and Assumptions :
For a target array the minimum number of operations is 5.
[0,0,0] -> [1,0,0] -> [1,1,0] -> [1,1,1] -> [2, 2, 2] -> [2, 2, 3]
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
We only need to iterate once through the list.
python3
The number of doubling done to the list equals to the number of times we have doubled the maximum number of that list.