3326. Minimum Division Operations to Make Array Non Decreasing Medium

@problem@discussion
#Array#Math#Greedy#Number Theory



1/**
2 * [3326] Minimum Division Operations to Make Array Non Decreasing
3 *
4 * You are given an integer array nums.
5 * Any positive divisor of a natural number x that is strictly less than x is called a proper divisor of x. For example, 2 is a proper divisor of 4, while 6 is not a proper divisor of 6.
6 * You are allowed to perform an operation any number of times on nums, where in each operation you select any one element from nums and divide it by its greatest proper divisor.
7 * Return the minimum number of operations required to make the array non-decreasing.
8 * If it is not possible to make the array non-decreasing using any number of operations, return -1.
9 *  
10 * <strong class="example">Example 1:
11 * <div class="example-block">
12 * Input: <span class="example-io">nums = [25,7]</span>
13 * Output: <span class="example-io">1</span>
14 * Explanation:
15 * Using a single operation, 25 gets divided by 5 and nums becomes [5, 7].
16 * </div>
17 * <strong class="example">Example 2:
18 * <div class="example-block">
19 * Input: <span class="example-io">nums = [7,7,6]</span>
20 * Output: <span class="example-io">-1</span>
21 * </div>
22 * <strong class="example">Example 3:
23 * <div class="example-block">
24 * Input: <span class="example-io">nums = [1,1,1,1]</span>
25 * Output: <span class="example-io">0</span>
26 * </div>
27 *  
28 * Constraints:
29 * 
30 * 	1 <= nums.length <= 10^5
31 * 	1 <= nums[i] <= 10^6
32 * 
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/minimum-division-operations-to-make-array-non-decreasing/
37// discuss: https://leetcode.com/problems/minimum-division-operations-to-make-array-non-decreasing/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42    pub fn min_operations(nums: Vec<i32>) -> i32 {
43        0
44    }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_3326() {
55    }
56}
57


Back
© 2025 bowen.ge All Rights Reserved.