Class Solution
java.lang.Object
g2601_2700.s2601_prime_subtraction_operation.Solution
2601 - Prime Subtraction Operation.<p>Medium</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p>
<p>You can perform the following operation as many times as you want:</p>
<ul>
<li>Pick an index <code>i</code> that you haven\u2019t picked before, and pick a prime <code>p</code> <strong>strictly less than</strong> <code>nums[i]</code>, then subtract <code>p</code> from <code>nums[i]</code>.</li>
</ul>
<p>Return <em>true if you can make <code>nums</code> a strictly increasing array using the above operation and false otherwise.</em></p>
<p>A <strong>strictly increasing array</strong> is an array whose each element is strictly greater than its preceding element.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [4,9,6,10]</p>
<p><strong>Output:</strong> true</p>
<p><strong>Explanation:</strong> In the first operation: Pick i = 0 and p = 3, and then subtract 3 from nums[0], so that nums becomes [1,9,6,10]. In the second operation: i = 1, p = 7, subtract 7 from nums[1], so nums becomes equal to [1,2,6,10]. After the second operation, nums is sorted in strictly increasing order, so the answer is true.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [6,8,11,12]</p>
<p><strong>Output:</strong> true</p>
<p><strong>Explanation:</strong> Initially nums is sorted in strictly increasing order, so we don’t need to make any operations.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> nums = [5,8,3]</p>
<p><strong>Output:</strong> false</p>
<p><strong>Explanation:</strong> It can be proven that there is no way to perform operations to make nums sorted in strictly increasing order, so the answer is false.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 1000</code></li>
<li><code>1 <= nums[i] <= 1000</code></li>
<li><code>nums.length == n</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
primeSubOperation
public boolean primeSubOperation(int[] nums)
-