Trains the technique from
LeetCode 1574Shortest Subarray to be Removed to Make Array SortedThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A rail of gauges reads gauges. Remove exactly one stretch of neighbouring gauges, possibly an empty one, so that what is left, read in order, never falls: every remaining reading is at least the one before it.
Return the length of the shortest stretch that can be removed. Removing nothing counts, and so does removing all but one reading.
Example 1
The rail rises through 1, 2, 3 at the front and through 3, 5 at the back. Dropping the three readings 10, 4 and 2 that lie between them leaves 1, 2, 3, 3, 5, which never falls, and no shorter cut manages it.
Example 2
The rail falls at every step, so no two readings can survive together and four of the five have to go.
Example 3
Only the single 0 is out of place; dropping it leaves 1, 2, 3, 4, 5.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def find_length_of_shortest_subarray(gauges: list[int]) -> int:public int findLengthOfShortestSubarray(int[] gauges)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.