pyPython Practice LabFrom first print to final round
TOPIC 12 OF 18

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.

38 exercises8+ conceptsBeginner → interview context
Start this topic
WHAT YOU WILL PRACTISE

Core concepts

Perform linear searchPerform iterative binary searchFind first and last occurrenceSort with bubble sortSort with insertion sortMerge overlapping intervalsBuild product except selfFind the majority element
REUSABLE THINKING

Problem-solving patterns

  • search
  • binary search
  • binary search · boundary
  • bubble sort
  • insertion sort
PRACTICE OUTCOME

What this topic builds

Learn the idea once, use it across the exercises, and explain why your approach works.

ORDERED PRACTICE

All 38 problems in this topic

Work from top to bottom to build the concept gradually.

  1. #181
    Perform linear search: Find inventory code

    Locate the first occurrence of a code in an unsorted list.

    BeginnerPremium
  2. #182
    Perform linear search: Target missing

    Return -1 after checking the complete list.

    BeginnerPremium
  3. #183
    Perform iterative binary search: Find sorted record

    Locate a target in a sorted record list.

    IntermediatePremium
  4. #184
    Perform iterative binary search: Outside the range

    Return -1 when a target is larger than every element.

    IntermediatePremium
  5. #185
    Find first and last occurrence: Repeated target range

    Find the full index range occupied by a repeated target.

    IntermediatePremium
  6. #186
    Find first and last occurrence: Single occurrence

    Both boundaries are identical when the target appears once.

    IntermediatePremium
  7. #187
    Sort with bubble sort: Unsorted readings

    Sort a small list to practice adjacent swaps.

    IntermediatePremium
  8. #188
    Sort with bubble sort: Already sorted

    Exercise the early-exit optimization on sorted input.

    AdvancedPremium
  9. #189
    Sort with insertion sort: Nearly sorted scores

    Sort a nearly ordered list, a good case for insertion sort.

    AdvancedPremium
  10. #190
    Sort with insertion sort: Reverse order

    Exercise the maximum number of shifts for a short list.

    AdvancedPremium
  11. #191
    Merge overlapping intervals: Meeting blocks

    Merge overlapping meeting time blocks.

    AdvancedPremium
  12. #192
    Merge overlapping intervals: Touching intervals

    Treat intervals that meet at an endpoint as one continuous interval.

    AdvancedPremium
  13. #193
    Build product except self: Positive array

    For every position, multiply all other values.

    AdvancedPremium
  14. #194
    Build product except self: One zero

    A zero leaves only its own position with a nonzero product.

    AdvancedPremium
  15. #195
    Find the majority element: Clear majority

    Find the value occurring in more than half of the list.

    Interview-LevelPremium
  16. #196
    Find the majority element: Short majority

    Handle the smallest list with a repeated majority.

    Interview-LevelPremium
  17. #197
    Find longest substring without repeats: Mixed repeats

    Find the longest unique-character window in a common example.

    Interview-LevelPremium
  18. #198
    Find longest substring without repeats: All same character

    A string of identical characters has best window length one.

    Interview-LevelPremium
  19. #199
    Maximize one stock transaction: Profitable price history

    Find the best profit from exactly one buy followed by one later sale.

    Interview-LevelPremium
  20. #200
    Maximize one stock transaction: Falling market

    Return zero when no later selling price exceeds an earlier buying price.

    Interview-LevelPremium
  21. #201
    Find unique three-sum triplets: Two valid triplets

    List all unique triples whose sum is zero.

    Interview-LevelPremium
  22. #202
    Find unique three-sum triplets: No zero-sum triple

    Report None when no three values can make zero.

    Interview-LevelPremium
  23. #203
    Maximize water between lines: Mixed container heights

    Find the largest container area formed by two vertical lines.

    Interview-LevelPremium
  24. #204
    Maximize water between lines: Two-line minimum

    Handle the smallest valid input containing exactly two lines.

    Interview-LevelPremium
  25. #205
    Calculate trapped rain water: Classic elevation map

    Calculate total water trapped after rain across varied bars.

    Interview-LevelPremium
  26. #206
    Calculate trapped rain water: No basin

    A steadily rising elevation map cannot trap water.

    Interview-LevelPremium
  27. #207
    Find the longest consecutive run: Unsorted run

    Find the length of the longest consecutive sequence without sorting.

    Interview-LevelPremium
  28. #208
    Find the longest consecutive run: Duplicates inside a run

    Ignore duplicate values while measuring a consecutive sequence.

    Interview-LevelPremium
  29. #209
    Rotate a square matrix clockwise: Three-by-three image

    Rotate a small image matrix 90 degrees clockwise.

    Interview-LevelPremium
  30. #210
    Rotate a square matrix clockwise: Two-by-two matrix

    Verify the same in-place transformation on the smallest nontrivial square.

    Interview-LevelPremium
  31. #211
    Read a matrix in spiral order: Rectangular spiral

    Return a rectangular matrix in clockwise spiral order.

    Interview-LevelPremium
  32. #212
    Read a matrix in spiral order: Single column

    Avoid duplicate visits when the matrix has only one column.

    Interview-LevelPremium
  33. #213
    Set matrix rows and columns to zero: One internal zero

    Zero the complete row and column containing an original zero.

    Interview-LevelPremium
  34. #214
    Set matrix rows and columns to zero: Several original zeros

    Apply all row and column effects from multiple original zeros.

    Interview-LevelPremium
  35. #215
    Count subarrays with target sum: Repeated target sums

    Count every contiguous subarray whose sum equals the target.

    Interview-LevelPremium
  36. #216
    Count subarrays with target sum: Include negative values

    Use prefix counts where a sliding window would fail because values may be negative.

    Interview-LevelPremium
  37. #217
    Find the minimum covering window: Smallest covering substring

    Find the shortest source substring containing every required character with multiplicity.

    Interview-LevelPremium
  38. #218
    Find the minimum covering window: Impossible coverage

    Report None when the source cannot cover the required characters.

    Interview-LevelPremium