Completed
Available
Locked · open anytime

Level 1: Essential Algorithms Exercises

Level 1 teaches the handful of patterns that solve most everyday performance problems, and most first-round interview questions. Each exercise is a small job from a real codebase: find duplicate sign-ups, match two prices to a gift card, merge two sorted logs, check the brackets in a config file.

Some tests feed your function thousands of items and count the steps it takes. A nested loop that looks fine on five items fails there, with a clear "too slow" message instead of a frozen page. That is Big-O you can see. The Rate Limiter project combines a sliding window with two pointers, the way API gateways count requests.

The 10 exercises in this level

  1. 1 Big-O: Spot the Hidden Loop Why a set beats a list for lookups Find duplicate sign-ups in one pass with a set, and see why a nested loop or x in a list gets 100 times slower when the data grows 10 times. Start here — no prerequisites
  2. 2 Pair Sum with a Hash Map Two prices that match a gift card Find two products that add up exactly to a gift card's value in one pass, with a dict that remembers where each price was seen. Recommended first: Big-O: Spot the Hidden Loop
  3. 3 Counting with a Dictionary The most frequent word, in one pass Find the most frequent word in a text with one pass and a dict of counts, and avoid str.count(), which rescans the text and counts the inside of other words. Recommended first: Big-O: Spot the Hidden Loop
  4. 4 Merging Sorted Lists Two pointers over two server logs Merge two sorted lists of log timestamps into one with two pointers: each item is touched once, and the input lists stay unchanged. Recommended first: Big-O: Spot the Hidden Loop
  5. 5 Sliding Window The best k days of sales Find the best run of k consecutive days with a running total: add the day that enters, subtract the day that leaves, and start from the first window, not from zero. Recommended first: Merging Sorted Lists
  6. 6 Prefix Sums Answer many range questions fast Answer thousands of "how much did we sell between day a and day b?" questions with one list of running totals and one subtraction each. Recommended first: Sliding Window
  7. 7 Binary Search Find a timestamp in 20 steps, not a million Find the first log entry at or after a given time by halving a sorted list at each step, and keep the bounds right so the loop always ends. Recommended first: Merging Sorted Lists
  8. 8 Stack: Balanced Brackets Check the brackets in a config file Check that every bracket in a line of code is closed in the right order with a stack, where counting brackets is not enough. Recommended first: Big-O: Spot the Hidden Loop
  9. 9 Sorting with Tuple Keys A leaderboard with fair tie-breaks Rank players by score, highest first, with ties in alphabetical order: one tuple key, a negated number, and no reverse=True. Recommended first: Counting with a Dictionary
  10. 10 Project: Rate Limiter The busiest minute of an API Find the busiest window of an API's request log, the number a rate limiter checks, with a window that grows and shrinks as two pointers move forward. Recommended first: Sliding Window, Binary Search

Frequently asked questions

Do I need to know Python well before this course?
You should be comfortable with lists, dictionaries, loops and functions, roughly Level 1 and 2 of the Python course. Every exercise starts with a short lesson on the one pattern it needs.
How do the tests know my solution is too slow?
Some tests count the Python steps your function runs on a large input. A solution that loops over the data once stays far below the limit; one that compares every item with every other item goes over it and stops at once. Loops hidden inside built-ins, like `x in a_list`, count too: the tests use items whose comparisons run Python code.
Is this enough for coding interviews?
Level 1 covers the patterns behind most easy and many medium interview questions: hash maps, two pointers, sliding windows, binary search and stacks. Practising them until you spot them quickly matters more than memorising solutions.
Why not just use built-in functions like sorted() and bisect?
In real code you should. Here you write the pattern once yourself so you know what those functions cost and when a hidden loop, like x in a list, makes your code slow.