Skip to content

Commit 94de189

Browse files
min deviation
1 parent d534b86 commit 94de189

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

‎greedy_methods/minimize_deviation_in_array.py‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
"""
22
You are given an array nums of n positive integers.
33
4-
You can perform two types of operations on any element of the array any number of times:
4+
You can perform two types of operations on any
5+
element of the array any number of times:
56
67
If the element is even, divide it by 2.
7-
For example, if the array is [1,2,3,4], then you can do this operation on the last element, and the array will be [1,2,3,2].
8+
For example, if the array is [1,2,3,4], then you can do this operation
9+
on the last element, and the array will be [1,2,3,2].
810
If the element is odd, multiply it by 2.
9-
For example, if the array is [1,2,3,4], then you can do this operation on the first element, and the array will be [2,2,3,4].
10-
The deviation of the array is the maximum difference between any two elements in the array.
11+
For example, if the array is [1,2,3,4], then you can do this operation
12+
on the first element, and the array will be [2,2,3,4].
13+
The deviation of the array is the maximum difference between
14+
any two elements in the array.
1115
12-
Return the minimum deviation the array can have after performing some number of operations.
16+
Return the minimum deviation the array can have after performing
17+
some number of operations.
1318
"""
1419

1520
from heapq import heapify, heappop, heappush
16-
21+
1722

1823
class Solution:
1924
def minimum_deviation(self, nums) -> int:

0 commit comments

Comments
 (0)