Remove One Element to Make the Array Strictly Increasing - Problem

Imagine you have an array of integers that's almost perfect - it would be strictly increasing if you could just remove exactly one element! Your task is to determine whether this transformation is possible.

Given a 0-indexed integer array nums, return true if it can be made strictly increasing after removing exactly one element, or false otherwise.

Special case: If the array is already strictly increasing, you should return true (you can remove any element and still maintain the property).

Definition: An array is strictly increasing if nums[i-1] < nums[i] for each valid index i where 1 ≤ i < nums.length.

Examples:

  • [1, 2, 10, 5, 7]true (remove 10 to get [1, 2, 5, 7])
  • [2, 3, 1, 2]false (no single removal works)
  • [1, 2, 3]true (already strictly increasing)

Input & Output

example_1.py — Python
$ Input: [1,2,10,5,7]
Output: true
💡 Note: We can remove the element at index 2 (value 10) to get [1,2,5,7], which is strictly increasing.
example_2.py — Python
$ Input: [2,3,1,2]
Output: false
💡 Note: No single element removal can make this array strictly increasing. Removing any element still leaves violations.
example_3.py — Python
$ Input: [1,2,3]
Output: true
💡 Note: The array is already strictly increasing, so we can remove any element and it will still work.

Visualization

Tap to expand
Smart Staircase Inspection Strategy1324Violation!InspectorInspection Analysis✓ Step 1 → 3: Valid (+2)✗ Step 3 → 2: Violation (-1)✓ Step 2 → 4: Would be valid (+2)Smart Solution:• Remove step 3: [1,2,4] ✓• Remove step 2: [1,3,4] ✓Result: TRUEMultiple valid solutions found!Time: O(n) vs O(n²) brute force
Understanding the Visualization
1
Scan for Violations
Walk through the staircase and mark every place where a step is not higher than the previous one
2
Analyze Violation Pattern
If there are no violations, the staircase is perfect. If there are too many violations (>2), it's unfixable
3
Test Smart Candidates
For each violation point, test removing either the violating step or the step before it
4
Verify Solution
Check if any of these targeted removals creates a perfect ascending staircase
Key Takeaway
🎯 Key Insight: Instead of testing all n possible removals, we only need to test at most 4 candidates around violation points, reducing time complexity from O(n²) to O(n).

Time & Space Complexity

Time Complexity
⏱️
O(n)

Two passes through array, each taking O(n) time

n
2n
Linear Growth
Space Complexity
O(n)

Storage for violation positions in worst case

n
2n
Linearithmic Space

Constraints

  • 2 ≤ nums.length ≤ 1000
  • 1 ≤ nums[i] ≤ 1000
  • Must remove exactly one element
  • Resulting array must be strictly increasing (no equal elements allowed)
Asked in
Google 25 Amazon 18 Apple 15 Microsoft 12
38.0K Views
Medium Frequency
~15 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen