Can One Removal Restore Strict Order?

Quick Overview

Can One Removal Restore Strict Order?. Given nums, determine whether deleting exactly one entry can leave a strictly increasing sequence. Return true for an already strictly increasing array, since deleting any entry keeps it increasing.

Can One Removal Restore Strict Order?

Company: Appian

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Return whether removing exactly one element from `nums` can leave its remaining elements in strictly increasing order. Equality does not satisfy strict increase. As in the source contract, an already strictly increasing array returns true because one element can still be removed. ```cpp class Solution { public: bool canBeIncreasing(vector<int>& nums); }; ``` ### Examples **Example 1:** ```text nums = [2,8,4,6] Output: true Explanation: Removing 8 leaves [2,4,6]. ``` **Example 2:** ```text nums = [4,2,3,1] Output: false Explanation: Removing any single entry leaves at least one adjacent non-increasing pair. ``` ### Constraints - `2 <= nums.length <= 1000`. - `1 <= nums[i] <= 1000`. ### Clarifying Questions Strictly increasing forbids equality. The input array need not be modified. ```hint Inspect the structure At the first adjacent violation, can deleting an unrelated element repair that pair? ``` ### Reasoning checkpoints - Account for every possible successful single deletion and verify strict order across the newly adjacent entries. - Distinguish one removable violation from inputs that still fail after any one removal. ### Optional extensions Can you obtain the same result in one pass with constant auxiliary space?

Overview: Can One Removal Restore Strict Order?. Given nums, determine whether deleting exactly one entry can leave a strictly increasing sequence. Return true for an already strictly increasing array, since deleting any entry keeps it increasing.

Appian logo
Appian
May 29, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return whether removing exactly one element from nums can leave its remaining elements in strictly increasing order. Equality does not satisfy strict increase. As in the source contract, an already strictly increasing array returns true because one element can still be removed.

class Solution {
public:
    bool canBeIncreasing(vector<int>& nums);
};

Examples

Example 1:

nums = [2,8,4,6]
Output: true
Explanation: Removing 8 leaves [2,4,6].

Example 2:

nums = [4,2,3,1]
Output: false
Explanation: Removing any single entry leaves at least one adjacent non-increasing pair.

Constraints

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

Clarifying Questions Guidance

Strictly increasing forbids equality. The input array need not be modified.

Reasoning checkpoints

  • Account for every possible successful single deletion and verify strict order across the newly adjacent entries.
  • Distinguish one removable violation from inputs that still fail after any one removal.

Optional extensions

Can you obtain the same result in one pass with constant auxiliary space?