2601. Prime Subtraction Operation Medium
1/**
2 * [2601] Prime Subtraction Operation
3 *
4 * You are given a 0-indexed integer array nums of length n.
5 * You can perform the following operation as many times as you want:
6 *
7 * 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].
8 *
9 * Return true if you can make nums a strictly increasing array using the above operation and false otherwise.
10 * A strictly increasing array is an array whose each element is strictly greater than its preceding element.
11 *
12 * <strong class="example">Example 1:
13 *
14 * Input: nums = [4,9,6,10]
15 * Output: true
16 * 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].
17 * In the second operation: i = 1, p = 7, subtract 7 from nums[1], so nums becomes equal to [1,2,6,10].
18 * After the second operation, nums is sorted in strictly increasing order, so the answer is true.
19 * <strong class="example">Example 2:
20 *
21 * Input: nums = [6,8,11,12]
22 * Output: true
23 * Explanation: Initially nums is sorted in strictly increasing order, so we don't need to make any operations.
24 * <strong class="example">Example 3:
25 *
26 * Input: nums = [5,8,3]
27 * Output: false
28 * 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.
29 *
30 * Constraints:
31 *
32 * 1 <= nums.length <= 1000
33 * 1 <= nums[i] <= 1000
34 * <font face="monospace">nums.length == n</font>
35 *
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/prime-subtraction-operation/
40// discuss: https://leetcode.com/problems/prime-subtraction-operation/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45 pub fn prime_sub_operation(nums: Vec<i32>) -> bool {
46 false
47 }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_2601() {
58 }
59}
60
Back
© 2025 bowen.ge All Rights Reserved.