Trains the technique from
LeetCode 1493Longest Subarray of 1's After Deleting One ElementThis 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 turnstile writes one entry per minute into log: 1 when it answered the gate controller that minute and 0 when it did not.
Before the log is filed, exactly one entry must be struck out -- the operator is required to remove one minute, not allowed to skip the removal. The auditor then reads the resulting array and reports the length of its longest run of consecutive 1s.
Return the largest length the auditor can be made to report. If no 1 can survive the removal, return 0.
Example 1
Striking out the entry at index 2 leaves five 1s in a row.
Example 2
Every minute answered, and one entry still has to go, so three remain in a row.
Example 3
Striking out index 2 leaves [1, 1, 0, 1, 1, 1], whose longest run of 1s is three.
Example 4
The log holds no 1 at all, so no run of 1s can survive.
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 longest_subarray(log: list[int]) -> int:public int longestSubarray(int[] log)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.