One Pass
Running Extremes
Second Largest
Easy·
Two Running Maxima
O(n)O(1)
FIG. SECOND LARGEST● INTERACTIVE
visualization loads as you reach it
1796. Second Largest Digit in a String
Easy·
Two Running Maxima
O(n)O(1)
FIG. 1796 SECOND LARGEST DIGIT IN A STRING● INTERACTIVE
visualization loads as you reach it
Greedy Scan
2259. Remove Digit From Number to Maximize Result
Easy·
Greedy Scan
O(n)O(1)
FIG. 2259 REMOVE DIGIT FROM NUMBER TO MAXIMIZE RESULT● INTERACTIVE
visualization loads as you reach it
605. Can Place Flowers
Easy·
Greedy Scan
O(size)O(1)
FIG. 605 CAN PLACE FLOWERS● INTERACTIVE
visualization loads as you reach it
1827. Minimum Operations to Make the Array Increasing
Easy·
Greedy Scan
O(n)O(1)
FIG. 1827 MINIMUM OPERATIONS TO MAKE THE ARRAY INCREASING● INTERACTIVE
visualization loads as you reach it
Neighbor Lookup
Neither a window nor a running extreme - each position's answer depends only on the value sitting right next to it, so a single pass that reads one neighbor per index is enough, whichever direction it walks.
1844. Replace All Digits with Characters
Easy·
2 Approaches
Backward Pair Scan
O(2n + 26)O(n + 26)
Forward Scan
O(2n + 26)O(n + 26)
FIG. 1844 REPLACE ALL DIGITS WITH CHARACTERS BACKWARD● INTERACTIVE
visualization loads as you reach it
Index Arithmetic
The positions that matter are computable from the loop counter, so the scan can skip straight to them instead of testing every element on the way past.
1572. Matrix Diagonal Sum
Easy·
2 Approaches
Test Every Cell
O(n^2)O(1)
Walk the Two Diagonals
O(n)O(1)
FIG. 1572 DIAGONAL SUM SCAN● INTERACTIVE
visualization loads as you reach it
2319. Check if Matrix Is X-Matrix
Easy·
Test Every Cell Against Both Diagonals
O(n^2)O(1)
FIG. 2319 CHECK X MATRIX● INTERACTIVE
visualization loads as you reach it
Running Total
The pass accumulates one number instead of comparing positions - what the array should total, minus what it actually totals, is the answer.
268. Missing Number
Easy·
4 Approaches · 3 patterns
XOR Indices & Values↗ XOR
O(N)O(1)
Bitmask + log2↗ XOR
O(N)O(1)
Sum Formula
O(N)O(1)
Sort, then Find the First Gap↗ Binary Search + Sort
O(log N + N log N)O(sort)