Algorithm Foundations: Arrays, Searching, Sorting, and Hashing Python practice problems
Complexity, linear and binary search, sorted() trade-offs, prefix ideas, two pointers, sliding windows, and hash-map patterns.
Core concepts
Problem-solving patterns
- search
- binary search
- binary search · boundary
- bubble sort
- insertion sort
What this topic builds
Learn the idea once, use it across the exercises, and explain why your approach works.
All 38 problems in this topic
Work from top to bottom to build the concept gradually.
- #181Perform linear search: Find inventory codeBeginnerPremium
Locate the first occurrence of a code in an unsorted list.
- #182Perform linear search: Target missingBeginnerPremium
Return -1 after checking the complete list.
- #183Perform iterative binary search: Find sorted recordIntermediatePremium
Locate a target in a sorted record list.
- #184Perform iterative binary search: Outside the rangeIntermediatePremium
Return -1 when a target is larger than every element.
- #185Find first and last occurrence: Repeated target rangeIntermediatePremium
Find the full index range occupied by a repeated target.
- #186Find first and last occurrence: Single occurrenceIntermediatePremium
Both boundaries are identical when the target appears once.
- #187Sort with bubble sort: Unsorted readingsIntermediatePremium
Sort a small list to practice adjacent swaps.
- #188Sort with bubble sort: Already sortedAdvancedPremium
Exercise the early-exit optimization on sorted input.
- #189Sort with insertion sort: Nearly sorted scoresAdvancedPremium
Sort a nearly ordered list, a good case for insertion sort.
- #190Sort with insertion sort: Reverse orderAdvancedPremium
Exercise the maximum number of shifts for a short list.
- #191Merge overlapping intervals: Meeting blocksAdvancedPremium
Merge overlapping meeting time blocks.
- #192Merge overlapping intervals: Touching intervalsAdvancedPremium
Treat intervals that meet at an endpoint as one continuous interval.
- #193Build product except self: Positive arrayAdvancedPremium
For every position, multiply all other values.
- #194Build product except self: One zeroAdvancedPremium
A zero leaves only its own position with a nonzero product.
- #195Find the majority element: Clear majorityInterview-LevelPremium
Find the value occurring in more than half of the list.
- #196Find the majority element: Short majorityInterview-LevelPremium
Handle the smallest list with a repeated majority.
- #197Find longest substring without repeats: Mixed repeatsInterview-LevelPremium
Find the longest unique-character window in a common example.
- #198Find longest substring without repeats: All same characterInterview-LevelPremium
A string of identical characters has best window length one.
- #199Maximize one stock transaction: Profitable price historyInterview-LevelPremium
Find the best profit from exactly one buy followed by one later sale.
- #200Maximize one stock transaction: Falling marketInterview-LevelPremium
Return zero when no later selling price exceeds an earlier buying price.
- #201Find unique three-sum triplets: Two valid tripletsInterview-LevelPremium
List all unique triples whose sum is zero.
- #202Find unique three-sum triplets: No zero-sum tripleInterview-LevelPremium
Report None when no three values can make zero.
- #203Maximize water between lines: Mixed container heightsInterview-LevelPremium
Find the largest container area formed by two vertical lines.
- #204Maximize water between lines: Two-line minimumInterview-LevelPremium
Handle the smallest valid input containing exactly two lines.
- #205Calculate trapped rain water: Classic elevation mapInterview-LevelPremium
Calculate total water trapped after rain across varied bars.
- #206Calculate trapped rain water: No basinInterview-LevelPremium
A steadily rising elevation map cannot trap water.
- #207Find the longest consecutive run: Unsorted runInterview-LevelPremium
Find the length of the longest consecutive sequence without sorting.
- #208Find the longest consecutive run: Duplicates inside a runInterview-LevelPremium
Ignore duplicate values while measuring a consecutive sequence.
- #209Rotate a square matrix clockwise: Three-by-three imageInterview-LevelPremium
Rotate a small image matrix 90 degrees clockwise.
- #210Rotate a square matrix clockwise: Two-by-two matrixInterview-LevelPremium
Verify the same in-place transformation on the smallest nontrivial square.
- #211Read a matrix in spiral order: Rectangular spiralInterview-LevelPremium
Return a rectangular matrix in clockwise spiral order.
- #212Read a matrix in spiral order: Single columnInterview-LevelPremium
Avoid duplicate visits when the matrix has only one column.
- #213Set matrix rows and columns to zero: One internal zeroInterview-LevelPremium
Zero the complete row and column containing an original zero.
- #214Set matrix rows and columns to zero: Several original zerosInterview-LevelPremium
Apply all row and column effects from multiple original zeros.
- #215Count subarrays with target sum: Repeated target sumsInterview-LevelPremium
Count every contiguous subarray whose sum equals the target.
- #216Count subarrays with target sum: Include negative valuesInterview-LevelPremium
Use prefix counts where a sliding window would fail because values may be negative.
- #217Find the minimum covering window: Smallest covering substringInterview-LevelPremium
Find the shortest source substring containing every required character with multiplicity.
- #218Find the minimum covering window: Impossible coverageInterview-LevelPremium
Report None when the source cannot cover the required characters.