Class Solution
-
- All Implemented Interfaces:
public final class Solution3326 - Minimum Division Operations to Make Array Non Decreasing.
Medium
You are given an integer array
nums.Any positive divisor of a natural number
xthat is strictly less thanxis called a proper divisor ofx. For example, 2 is a proper divisor of 4, while 6 is not a proper divisor of 6.You are allowed to perform an operation any number of times on
nums, where in each operation you select any one element fromnumsand divide it by its greatest proper divisor.Return the minimum number of operations required to make the array non-decreasing.
If it is not possible to make the array non-decreasing using any number of operations, return
-1.Example 1:
Input: nums = 25,7
Output: 1
Explanation:
Using a single operation, 25 gets divided by 5 and
numsbecomes[5, 7].Example 2:
Input: nums = 7,7,6
Output: \-1
Example 3:
Input: nums = 1,1,1,1
Output: 0
Constraints:
<code>1 <= nums.length <= 10<sup>5</sup></code>
<code>1 <= numsi<= 10<sup>6</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegerminOperations(IntArray nums)-
-
Method Detail
-
minOperations
final Integer minOperations(IntArray nums)
-
-
-
-