Count Removals Yielding a Strictly Increasing Array

Problem Given an array of integers, you may remove exactly one element. Count how many valid removals leave a strictly increasing sequence.

Input / Output

  • Input: array arr of integers.
  • Output: the number of valid removals. Clarify whether removals at different indices that yield the same sequence count once or twice.

Constraints

  • Length up to ~10^5.
  • The array may contain duplicates — ties matter, since strict increase forbids equality.
  • Exactly one element must be removed; removing zero is not permitted even if the array is already sorted.

Example

  • [1,3,2,4] → 2. Removing the 3 gives [1,2,4]; removing the 2 gives [1,3,4]. Both are strictly increasing.
  • [1,2,3,4,2] → 1. Only removing the trailing 2 works; removing the 4 leaves [1,2,3,2].
  • [5,3,4,2] → 0. Two separate violations, so no single removal repairs both.
  • Tricky case: [1,2,2,3] — removing either 2 produces [1,2,3]. That is 2 valid removals but only 1 distinct sequence, which is why the counting rule must be pinned down first.
asked …
LeaderboardSalaryAccount