Tap here to switch tabs
Problem
Submissions

Problem: Minimize Deviation in Array

med
30 min
Try to solve the Minimize Deviation in Array problem.

Statement

You are given an array nums consisting of nn positive integers.

You can perform two types of operations on any element in the array any number of times:

  • If the element is even, divide it by 22.

  • If the element is odd, multiply it by 22.

The deviation of the array is defined as the maximum difference between any two elements in the array.

Return the minimum deviation you can achieve after applying any number of operations.

Constraints:

  • n == nums.length

  • 2≤2 \leq n ≤5imes104\leq 5 imes 10^4

  • 1≤1 \leq nums[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimize Deviation in Array

med
30 min
Try to solve the Minimize Deviation in Array problem.

Statement

You are given an array nums consisting of nn positive integers.

You can perform two types of operations on any element in the array any number of times:

  • If the element is even, divide it by 22.

  • If the element is odd, multiply it by 22.

The deviation of the array is defined as the maximum difference between any two elements in the array.

Return the minimum deviation you can achieve after applying any number of operations.

Constraints:

  • n == nums.length

  • 2≤2 \leq n ≤5imes104\leq 5 imes 10^4

  • 1≤1 \leq nums[i] ≤109\leq 10^9