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
arrof 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 the3gives[1,2,4]; removing the2gives[1,3,4]. Both are strictly increasing.[1,2,3,4,2]→1. Only removing the trailing2works; removing the4leaves[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 either2produces[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 …