|
| 1 | +<h2><a href="https://leetcode.com/problems/prime-subtraction-operation/">2601. Prime Subtraction Operation</a></h2><h3>Medium</h3><hr><div><p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p> |
| 2 | + |
| 3 | +<p>You can perform the following operation as many times as you want:</p> |
| 4 | + |
| 5 | +<ul> |
| 6 | + <li>Pick an index <code>i</code> that you haven’t 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> |
| 7 | +</ul> |
| 8 | + |
| 9 | +<p>Return <em>true if you can make <code>nums</code> a strictly increasing array using the above operation and false otherwise.</em></p> |
| 10 | + |
| 11 | +<p>A <strong>strictly increasing array</strong> is an array whose each element is strictly greater than its preceding element.</p> |
| 12 | + |
| 13 | +<p> </p> |
| 14 | +<p><strong class="example">Example 1:</strong></p> |
| 15 | + |
| 16 | +<pre><strong>Input:</strong> nums = [4,9,6,10] |
| 17 | +<strong>Output:</strong> true |
| 18 | +<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]. |
| 19 | +In the second operation: i = 1, p = 7, subtract 7 from nums[1], so nums becomes equal to [1,2,6,10]. |
| 20 | +After the second operation, nums is sorted in strictly increasing order, so the answer is true.</pre> |
| 21 | + |
| 22 | +<p><strong class="example">Example 2:</strong></p> |
| 23 | + |
| 24 | +<pre><strong>Input:</strong> nums = [6,8,11,12] |
| 25 | +<strong>Output:</strong> true |
| 26 | +<strong>Explanation: </strong>Initially nums is sorted in strictly increasing order, so we don't need to make any operations.</pre> |
| 27 | + |
| 28 | +<p><strong class="example">Example 3:</strong></p> |
| 29 | + |
| 30 | +<pre><strong>Input:</strong> nums = [5,8,3] |
| 31 | +<strong>Output:</strong> false |
| 32 | +<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.</pre> |
| 33 | + |
| 34 | +<p> </p> |
| 35 | +<p><strong>Constraints:</strong></p> |
| 36 | + |
| 37 | +<ul> |
| 38 | + <li><code>1 <= nums.length <= 1000</code></li> |
| 39 | + <li><code>1 <= nums[i] <= 1000</code></li> |
| 40 | + <li><code><font face="monospace">nums.length == n</font></code></li> |
| 41 | +</ul> |
| 42 | +</div> |
0 commit comments