Description
You are given an array nums of n positive integers. You can perform two types of operations: if element is even, divide by 2; if element is odd, multiply by 2. Return the minimum difference between the maximum and minimum element after performing operations.
Examples
Input:
nums = [1,2,3,4]Output:
1Explanation:
Start with [6, 10, 15]. Odd numbers can double and even numbers can halve. Through optimal operations, the array reaches [5, 6, 8] (or equivalent) with minimum deviation of 7.
Input:
nums = [6, 10, 15]Output:
9Explanation:
After the allowed operations are applied optimally, the minimum achievable deviation is 9.
Input:
nums = [7, 8]Output:
1Explanation:
Start with [7, 8]. Multiply 7 by 2: [14, 8]. Divide 8 by 2: [14, 4]. The deviation is 10. Alternatively: [7, 8] -> [7, 4] gives deviation 3. Further: [14, 8] -> [7, 8] gives deviation 1, the minimum achievable.
Constraints
- •
n == nums.length - •
2 ≤ n ≤ 5 * 10^4