Prime Subtraction Operation

You are given a 0-indexed integer array nums of length n.

You can perform the following operation as many times as you want:

  • Pick an index i that you haven’t picked before, and pick a prime p strictly less than nums[i], then subtract p from nums[i].

Return true if you can make nums a strictly increasing array using the above operation and false otherwise.

A strictly increasing array is an array whose each element is strictly greater than its preceding element.

Example 1
Inputnums = [4,9,6,10]
Outputtrue
After subtracting 3 from nums[0] and 7 from nums[1], nums becomes [1, 2, 6, 10], which is strictly increasing.
Example 2
Inputnums = [6,8,11,12]
Outputtrue
Initially nums is sorted in strictly increasing order, so no operations are needed.

Constraints

  • 1 <= nums.length <= 1000
  • 1 <= nums[i] <= 1000
  • nums.length == n

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate