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).
26 STAGES
☆☆☆☆☆ Clear any 5 stages to beat this world, or all 26 for 100%.
EASY2:09Best Time to Buy and Sell Stock
One passLC 121▶ START
MEDIUM2:00Merge Intervals
SortingLC 56▶ START
MEDIUM2:09Group Anagrams
Hash mapLC 49▶ START
MEDIUM1:56Top K Frequent
HeapLC 347▶ START
MEDIUM2:04Kth Largest Element in an Array
SortingLC 215▶ START
MEDIUM2:05Longest Consecutive Sequence
Hash setLC 128▶ START
MEDIUM2:07Longest Substring
Sliding windowLC 3▶ START
MEDIUM2:09Permutation in String
Sliding windowLC 567▶ START
MEDIUM2:10Longest Repeating Character Replacement
Sliding windowLC 424▶ START
HARD2:05Minimum Window Substring
Sliding windowLC 76▶ START
HARD2:09Sliding Window Maximum
Monotonic dequeLC 239▶ START
MEDIUM2:04Subarray Sum Equals K
Prefix sumsLC 560▶ START
MEDIUM2:11Product of Array Except Self
Prefix and suffix productsLC 238▶ START
HARD2:05First Missing Positive
Cyclic sortLC 41▶ START
MEDIUM2:13Two Sum II - Input Array Is Sorted
Two pointersLC 167▶ START
MEDIUM2:123Sum
Two pointersLC 15▶ START
MEDIUM2:11Container With Most Water
Two pointersLC 11▶ START
MEDIUM2:09Sort Colors
Two pointersLC 75▶ START
MEDIUM2:10Evaluate Reverse Polish Notation
StackLC 150▶ START
MEDIUM2:11Daily Temperatures
Monotonic stackLC 739▶ START
HARD2:06Trapping Rain Water
Two pointersLC 42▶ START
HARD2:04Largest Rectangle in Histogram
Monotonic stackLC 84▶ START
MEDIUM2:11Search a 2D Matrix
Binary searchLC 74▶ START
MEDIUM2:11Search in Rotated Sorted Array
Binary searchLC 33▶ START
MEDIUM2:13Koko Eating Bananas
Binary searchLC 875▶ START
HARD2:07Median of Two Sorted Arrays
Binary searchLC 4▶ START