WORLD 2
ARRAYS
One-pass scans, sort and sweep, a leaderboard, a sliding window, running totals, two pointers and a stack.
STAGE 0 Arrays tutorial
0:00 / 0:00
The move
Walk the array once while keeping a little state instead of restarting at every position. Two pointers close in from the ends of a sorted row; a sliding window grows on the right and shrinks on the left; a running total turns any range sum into one subtraction.
- Spot it
- A contiguous subarray or substring, a pair in a sorted array, a range sum, or the best so far in one pass.
- Cost
- Each pointer moves one way, so it's O(n) time and O(1) extra space; sorting first adds O(n log n).
18 STAGES Arrays problems
☆☆☆☆☆ Clear 5 to finish this world.
EASY1:32Best Time to Buy and Sell Stock
One passLC 121▶ START
MEDIUM1:39Merge Intervals
SortingLC 56▶ START
MEDIUM1:34Group Anagrams
Hash mapLC 49▶ START
MEDIUM1:32Top K Frequent
HeapLC 347▶ START
MEDIUM1:35Longest Consecutive Sequence
Hash setLC 128▶ START
MEDIUM1:35Longest Substring
Sliding windowLC 3▶ START
HARD1:42Minimum Window Substring
Sliding windowLC 76▶ START
HARD1:37Sliding Window Maximum
Monotonic dequeLC 239▶ START
MEDIUM1:35Subarray Sum Equals K
Prefix sumsLC 560▶ START
MEDIUM1:42Product of Array Except Self
Prefix and suffix productsLC 238▶ START
MEDIUM1:453Sum
Two pointersLC 15▶ START
MEDIUM1:42Container With Most Water
Two pointersLC 11▶ START
MEDIUM1:56Evaluate Reverse Polish Notation
StackLC 150▶ START
MEDIUM1:48Daily Temperatures
Monotonic stackLC 739▶ START
HARD1:35Trapping Rain Water
Two pointersLC 42▶ START
HARD1:35Largest Rectangle in Histogram
Monotonic stackLC 84▶ START
MEDIUM1:35Search in Rotated Sorted Array
Binary searchLC 33▶ START
HARD1:44Median of Two Sorted Arrays
Binary searchLC 4▶ START