Off-by-one on range boundaries
Wrong move: Loop endpoints miss first/last candidate.
Usually fails on: Fails on minimal arrays and exact-boundary answers.
Fix: Re-derive loops from inclusive/exclusive ranges before coding.
Build confidence with an intuition-first walkthrough focused on array fundamentals.
Given a 0-indexed integer array nums, return true if it can be made strictly increasing after removing exactly one element, or false otherwise. If the array is already strictly increasing, return true.
The array nums is strictly increasing if nums[i - 1] < nums[i] for each index (1 <= i < nums.length).
Example 1:
Input: nums = [1,2,10,5,7] Output: true Explanation: By removing 10 at index 2 from nums, it becomes [1,2,5,7]. [1,2,5,7] is strictly increasing, so return true.
Example 2:
Input: nums = [2,3,1,2] Output: false Explanation: [3,1,2] is the result of removing the element at index 0. [2,1,2] is the result of removing the element at index 1. [2,3,2] is the result of removing the element at index 2. [2,3,1] is the result of removing the element at index 3. No resulting array is strictly increasing, so return false.
Example 3:
Input: nums = [1,1,1] Output: false Explanation: The result of removing any element is [1,1]. [1,1] is not strictly increasing, so return false.
Constraints:
2 <= nums.length <= 10001 <= nums[i] <= 1000Problem summary: Given a 0-indexed integer array nums, return true if it can be made strictly increasing after removing exactly one element, or false otherwise. If the array is already strictly increasing, return true. The array nums is strictly increasing if nums[i - 1] < nums[i] for each index (1 <= i < nums.length).
Start with the most direct exhaustive search. That gives a correctness anchor before optimizing.
Pattern signal: Array
[1,2,10,5,7]
[2,3,1,2]
[1,1,1]
steps-to-make-array-non-decreasing)find-the-maximum-factor-score-of-array)Source-backed implementations are provided below for direct study and interview prep.
// Accepted solution for LeetCode #1909: Remove One Element to Make the Array Strictly Increasing
class Solution {
public boolean canBeIncreasing(int[] nums) {
int i = 0;
while (i + 1 < nums.length && nums[i] < nums[i + 1]) {
++i;
}
return check(nums, i) || check(nums, i + 1);
}
private boolean check(int[] nums, int k) {
int pre = 0;
for (int i = 0; i < nums.length; ++i) {
if (i == k) {
continue;
}
if (pre >= nums[i]) {
return false;
}
pre = nums[i];
}
return true;
}
}
// Accepted solution for LeetCode #1909: Remove One Element to Make the Array Strictly Increasing
func canBeIncreasing(nums []int) bool {
check := func(k int) bool {
pre := 0
for i, x := range nums {
if i == k {
continue
}
if pre >= x {
return false
}
pre = x
}
return true
}
i := 0
for i+1 < len(nums) && nums[i] < nums[i+1] {
i++
}
return check(i) || check(i+1)
}
# Accepted solution for LeetCode #1909: Remove One Element to Make the Array Strictly Increasing
class Solution:
def canBeIncreasing(self, nums: List[int]) -> bool:
def check(k: int) -> bool:
pre = -inf
for i, x in enumerate(nums):
if i == k:
continue
if pre >= x:
return False
pre = x
return True
i = 0
while i + 1 < len(nums) and nums[i] < nums[i + 1]:
i += 1
return check(i) or check(i + 1)
// Accepted solution for LeetCode #1909: Remove One Element to Make the Array Strictly Increasing
impl Solution {
pub fn can_be_increasing(nums: Vec<i32>) -> bool {
let check = |k: usize| -> bool {
let mut pre = 0;
for (i, &x) in nums.iter().enumerate() {
if i == k {
continue;
}
if pre >= x {
return false;
}
pre = x;
}
true
};
let mut i = 0;
while i + 1 < nums.len() && nums[i] < nums[i + 1] {
i += 1;
}
check(i) || check(i + 1)
}
}
// Accepted solution for LeetCode #1909: Remove One Element to Make the Array Strictly Increasing
function canBeIncreasing(nums: number[]): boolean {
const n = nums.length;
const check = (k: number): boolean => {
let pre = 0;
for (let i = 0; i < n; ++i) {
if (i === k) {
continue;
}
if (pre >= nums[i]) {
return false;
}
pre = nums[i];
}
return true;
};
let i = 0;
while (i + 1 < n && nums[i] < nums[i + 1]) {
++i;
}
return check(i) || check(i + 1);
}
Use this to step through a reusable interview workflow for this problem.
Two nested loops check every pair or subarray. The outer loop fixes a starting point, the inner loop extends or searches. For n elements this gives up to n²/2 operations. No extra space, but the quadratic time is prohibitive for large inputs.
Most array problems have an O(n²) brute force (nested loops) and an O(n) optimal (single pass with clever state tracking). The key is identifying what information to maintain as you scan: a running max, a prefix sum, a hash map of seen values, or two pointers.
Review these before coding to avoid predictable interview regressions.
Wrong move: Loop endpoints miss first/last candidate.
Usually fails on: Fails on minimal arrays and exact-boundary answers.
Fix: Re-derive loops from inclusive/exclusive ranges before coding.