Practice With a Plan

You’re sitting across from an interviewer, the problem is up on the screen, and you already know how to write a loop. But which loop? And how do you explain why it works while someone watches you type? That’s the part of a coding interview that takes practice, and it’s what you’ll train in this course.

You’ll work through twenty exercises on arrays and strings, practicing hashing, two pointers, and sliding windows with Python lists, dictionaries, and sets. If some of that feels a little rusty, that’s okay! You’ll learn a lot just by getting started.

Each pattern section opens with a short introduction and six exercises. The mixed practice section leaves out the pattern name, so you get to choose the approach yourself, and then you’ll try a mock interview. Every section ends with a recap. For each problem, work through this cycle:

Five steps from clarifying requirements to explaining a solution, with a return arrow from testing to planning.
From a First Idea to an Explained Solution

Before you type, grab a pen and paper and walk a small input through by hand. What should you return? May you change the input? What about an empty list? Then sketch a first approach, even one that repeats work. That slow version shows you exactly where a better idea could save effort.

The time and extra-space bounds in each exercise are requirements. O(n) time means the total work grows at most in proportion to the input size, and O(1) extra space means the memory you add stays bounded however large the input gets. Keep in mind that Python operations have costs of their own. Indexing a list is quick, while checking a list with in may scan every item. For a refresher, take a look at Python’s data structures.

Expect a few red tests along the way. Read each failure message before you change your code, and open one hint at a time when you’re stuck. Once your tests pass, use the reasoning review to explain what your code costs, because your explanation needs to hold up beyond the inputs the tests check.

Got your pen and paper ready? Have fun practicing!

Free Bonus: Python Time and Space Complexity Cheat Sheet

Get a Python Time and Space Complexity Cheat Sheet (PDF) with the Big O costs of lists, dicts, sets, deques, heaps, sorting, and recursion on one page:

Python Time and Space Complexity Cheat Sheet

Become a Member to join the conversation.