Remove One Element to Make the Array Strictly Increasing

EasyArrays & Hashinggreedy

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

Given an integer array nums with at least two elements, return true if deleting **exactly one** element leaves an array that is strictly increasing, and false otherwise. An array is strictly increasing when every element is greater than the one before it. If nums is already strictly increasing, the answer is true, because removing an end element keeps it strictly increasing. Aim for a single O(n) pass.

Examples

Input: nums = [1,2,10,5,7]
Output: true
Removing 10 leaves [1,2,5,7].
Input: nums = [2,3,1,2]
Output: false
Every single removal leaves an array with a non-increase.
Input: nums = [1,1,1]
Output: false
Any removal leaves [1,1].

Constraints

  • 2 <= nums.length <= 1000
  • 1 <= nums[i] <= 1000 (tests may also use 0)

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More greedy problems