Check whether removing exactly one element makes an array strictly increasing

Quick Overview

Given an integer array, decide whether removing exactly one element can leave it strictly increasing. Tests single-pass greedy reasoning about which of two conflicting neighbors to drop, along with edge cases such as equal values and arrays that are already sorted.

Check whether removing exactly one element makes an array strictly increasing

Company: eBay

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

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 `i` with `1 <= i < len(nums)`. ### Function Signature ```python def can_be_increasing(nums: List[int]) -> bool: ``` ### Rules - Exactly one element is removed, and the remaining elements keep their original order. - Equal neighbors break the strictly increasing property. ### Constraints - `2 <= len(nums) <= 1000` - `1 <= nums[i] <= 1000` ### Examples ```text Input: nums = [1, 2, 10, 5, 7] Output: True ``` Removing the element at index 2 (value 10) gives `[1, 2, 5, 7]`, which is strictly increasing. ```text Input: nums = [2, 3, 1, 2] Output: False ``` The four possible removals give `[3, 1, 2]`, `[2, 1, 2]`, `[2, 3, 2]` and `[2, 3, 1]`, and none of them is strictly increasing. ```text Input: nums = [1, 2, 3] Output: True ``` The array is already strictly increasing. Removing any one element, for example the last, leaves `[1, 2]`, which is still strictly increasing.

Overview: Given an integer array, decide whether removing exactly one element can leave it strictly increasing. Tests single-pass greedy reasoning about which of two conflicting neighbors to drop, along with edge cases such as equal values and arrays that are already sorted.

eBay logo
eBay
Nov 25, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

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 i with 1 <= i < len(nums).

Function Signature

def can_be_increasing(nums: List[int]) -> bool:

Rules

  • Exactly one element is removed, and the remaining elements keep their original order.
  • Equal neighbors break the strictly increasing property.

Constraints

  • 2 <= len(nums) <= 1000
  • 1 <= nums[i] <= 1000

Examples

Input: nums = [1, 2, 10, 5, 7]
Output: True

Removing the element at index 2 (value 10) gives [1, 2, 5, 7], which is strictly increasing.

Input: nums = [2, 3, 1, 2]
Output: False

The four possible removals give [3, 1, 2], [2, 1, 2], [2, 3, 2] and [2, 3, 1], and none of them is strictly increasing.

Input: nums = [1, 2, 3]
Output: True

The array is already strictly increasing. Removing any one element, for example the last, leaves [1, 2], which is still strictly increasing.