Python interview preparation
A coding interview asks you to explain why a solution works and how its cost grows. This course connects those explanations to Python implementations for easy and medium problems. The examples use integers, strings, nodes, and graphs, so you can focus on the algorithm.
Start with Big O and the interview method. Then study the structures before the patterns that use them. Use the practice plan to solve new problems without copying a solution.
Prerequisites
Section titled “Prerequisites”You need Python variables, conditions, loops, functions, and basic classes. The existing lessons on control flow, functions, and classes cover that syntax. The type annotation lesson explains the annotations in this course.
A Python list stores an indexed sequence and behaves as a dynamic array in CPython.
A linked list stores nodes connected by references.
These representations support different operations, although both contain a sequence of values.
The course gives each representation its own lesson.
Course route
Section titled “Course route”Each worked lesson includes a problem, a state trace, executable Python, and an explanation of time and auxiliary space. Some external exercises repeat a worked problem; others change its requirements. The practice plan labels that distinction. The mixed practice page has three problems with concealed hints and solutions for independent method selection.
| Order | Lesson | Question to answer | Video and captions |
|---|---|---|---|
| 1 | Big O and interview method | How many operations does the implementation need as the input grows? | Watch and captions. |
| 2 | Arrays and Python lists | Which operations move references, and which change one position? | Watch and captions. |
| 3 | Hash maps | Which earlier information must the algorithm retrieve? | Watch and captions. |
| 4 | Sets | Does the problem need membership, counts, or order? | Watch and captions. |
| 5 | Stacks | Which unfinished item must the algorithm handle next? | Watch and captions. |
| 6 | Queues | Which waiting item arrived first? | Watch and captions. |
| 7 | Linked lists | Which reference must survive before a link changes? | Watch and captions. |
| 8 | Trees | What does each recursive call return for its subtree? | Watch and captions. |
| 9 | Heaps | Which candidate belongs at the root? | Watch and captions. |
| 10 | Graphs | When does a vertex become visited? | Watch and captions. |
| 11 | Two pointers and sliding windows | What remains true when a boundary moves? | Watch and captions. |
| 12 | Binary search, sorting, and intervals | What lets the algorithm discard candidates or merge intervals? | Watch and captions. |
| 13 | Recursion and backtracking | What choice does the algorithm undo before it tries another? | Watch and captions. |
| 14 | Dynamic programming | Which smaller states determine the current state? | Watch and captions. |
| 15 | Monotonic stacks | Which unresolved indices can the current value answer? | Watch and captions. |
| 16 | Topological sorting | Which tasks have no unfinished prerequisites? | Watch and captions. |
| 17 | Union-find | Do two vertices already belong to the same component? | No video. |
| 18 | Greedy methods | Why can one local choice preserve an optimal solution? | No video. |
| 19 | Two-dimensional dynamic programming | What does each pair of indices represent in the recurrence? | Watch and captions. |
If you already write Python, use the Python refresher route to check language details before these algorithms. For interviews, practice selecting the method from an unfamiliar problem statement. Being able to repeat a worked solution does not establish that you can select its method.
Learn a pattern through its invariant
Section titled “Learn a pattern through its invariant”An invariant is a statement that remains true after each step. For a sliding window, it might state that the current substring contains no repeated character. For binary search, it identifies the part of the array that can still contain the answer. Write that statement before you write the loop.
The data structure follows from the information you need to preserve. A set records whether a value exists, while a dictionary can also record its count or latest position. A queue preserves arrival order, while a heap selects by priority. Choose the operation first, then choose its Python representation.
Explain complexity aloud
Section titled “Explain complexity aloud”Define the input size before you name a cost.
An array problem often uses n for its length; a graph problem usually needs both vertex and edge counts.
Count work inside the loop, including slices, copies, searches, and sorts.
Two nested loops do not automatically imply quadratic time if their boundaries only move forward.
State auxiliary space separately from the input and required output. Include the recursion stack and any temporary copy. For dictionary and set operations, say when the claim assumes expected constant time. The complexity lesson explains these distinctions with operation counts.
Further reading
Section titled “Further reading”Download the complete Python examples to run the lessons locally. The archive contains nineteen lesson scripts, one mixed practice script, and instructions for Python 3.13.18 through uv. Each lesson also links its individual script.
The Python tutorial on data structures explains the built-in containers and their methods. Use it to check syntax while you work through the structure lessons.
The individual lessons link the Python documentation and algorithm sources relevant to their implementations. The practice plan connects those lessons to public LeetCode problems.