#2601
Prime Subtraction Operation
specialist · 790 · lc medium +31 · verified · 55.6% accepted · 941 likes · top 49%
Description
You are given a 0-indexed integer array nums of length n. At most once per index, you may subtract a prime p (with p < nums[i]) from nums[i]. Return true if nums can be made strictly increasing this way, or false otherwise.
Example 1:
Input: nums = [4,9,6,10]
Output: true
Explanation: 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.
Example 2:
Input: nums = [6,8,11,12]
Output: true
Explanation: Initially nums is sorted in strictly increasing order, so we don't need to make any operations.
Example 3:
Input: nums = [5,8,3]
Output: false
Explanation: 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.
Code
1
2
3