Narrowest Spread
You may change the numbers of nums with two kinds of moves, as often as you like: an even number may be halved, and an odd number may be doubled.
The spread of the list is its largest number minus its smallest number. Return the smallest spread you can reach.
Example 1
nums [3,10,7]
returns 2
Double 3 and halve 10: the list becomes 6, 5, 7.
Example 2
nums [8,1]
returns 0
Double 1 and halve 8 twice: both numbers are 2.
Example 3
nums [5,5]
returns 0
The numbers are equal already.
Constraints
2 <= len(nums) <= 301 <= nums[i] <= 10**9
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Greedy problems
- Saw, Then PaintHard
- Seat the Pairs TogetherHard
- Two From Every IntervalHard
- Coins Handed BackBeginner
- Coins on the TableBeginner
- Fewest BanknotesBeginner
- Fewest JugsBeginner
- Greedy CoinsBeginner