Skip to content
Coding

Coding Interview Prep: Data Structures and Algorithms

A free course for software engineering interviews. It teaches Big-O, hashing, two pointers, sliding windows, stacks and queues, binary search, linked lists, trees, heaps and an introduction to dynamic programming, each with an original Python problem tested in your browser. It also shows how to talk through a problem the way interviewers expect.

Coding Interview Prep: Data Structures and Algorithms 10 lessons 4 hours of lessons 69 practice questions Free
The course

Every lesson, in order

Planned as 8 weeks at 4 sessions a week, about 45 minutes each. Each lesson opens here in full; in BiliMind your answers are marked and your flashcards come back before you forget them.

10 topics · 3 hr 54m
0% done
Recommended Alternative Learn anytimeChecked from memory Checked from memoryRead ReadLearning LearningNot started Not started

Coding Interview Prep: DataStructures and Algorithms

Start here The finish line
  1. Estimate how fast a solution grows, and follow a repeatable method from clarifying questions to testing.

    • Big-O describes how work grows with input size: O(1), O(log n), O(n), O(n log n), O(n²).
    • For n near 10⁵ or more, O(n²) is too slow; look for a set, a dict, sorting or two pointers.
    • Follow the method: clarify, examples, brute force, improve, code, test, state complexity.
    • Think out loud: the process is part of the answer.
  2. Use sets and dictionaries to turn nested loops into a single pass.

    • A set or dict turns "search the rest of the list" into an O(1) lookup, so O(n²) becomes O(n).
    • Three patterns: seen-before (set), counting/grouping (dict), complement lookup (value to index).
    • Check for the partner **before** you store the current item.
    • You trade O(n) memory for time; say so out loud.
  3. Walk two indexes through a list, usually from both ends, to solve in O(n) without extra memory.

    • Two pointers replace a nested loop with one pass: O(n) time, O(1) space.
    • Opposite-end pointers need sorted data or symmetry; same-direction pointers (slow and fast) work in place.
    • Always know why moving a pointer cannot lose an answer.
    • Guard loops with `l < r` so the pointers never cross.
  4. Slide a window over a list, adding on one side and removing on the other, to answer subarray questions in O(n).

    • A sliding window updates a running answer as one item enters and one leaves, instead of recomputing: O(n).
    • Fixed windows add `a[i]` and subtract `a[i - k]`.
    • Variable windows grow with `right` and shrink with `left` while a condition holds; `left` never goes backwards.
    • Needs a monotonic measure, such as sums of positive numbers.
  5. Use last-in-first-out and first-in-first-out containers for matching, undo and ordering problems.

    • A stack is last-in, first-out; use a list with `append` and `pop`.
    • A queue is first-in, first-out; use `collections.deque` with `append` and `popleft`.
    • Reach for a stack for matching, nesting, undo and expression evaluation.
    • Check three failure cases in matching problems: closer with no opener, wrong type, openers left over.
  6. Halve the search space each step on sorted data, and on any yes/no answer that flips once.

    • Binary search halves the range each step: O(log n) on sorted data.
    • The reliable template finds the first index where a condition becomes true: `lo = mid + 1` or `hi = mid`.
    • You can binary search a numeric answer when a yes/no check flips once, as in "smallest capacity that works".
    • Test with 0, 1 and 2 items to catch off-by-one and infinite loops.
  7. Work with nodes and pointers: reverse a list and find its middle with the slow and fast pointer trick.

    • A linked list is nodes with `val` and `next`; you hold the head.
    • Reaching item `i` costs O(i), but inserting or deleting after a known node is O(1).
    • Reverse with `prev`, `cur` and a saved `next`; slow and fast pointers find the middle or a cycle.
    • Check empty, one-node and two-node lists, and use a dummy node to simplify deletion.
  8. Traverse a binary tree depth-first with recursion and breadth-first with a queue.

    • A binary tree node has `val`, `left` and `right`; `None` marks no child.
    • DFS with recursion: base case on `None`, recurse on both children, combine the results.
    • BFS uses a queue; freeze `len(queue)` to process one level per round.
    • Both visit every node once: O(n) time.
  9. Use a priority queue to keep the smallest or largest items while data streams in.

    • `heapq` is a min-heap on a list: `heappush`, `heappop`, `h[0]` in O(log n), O(log n) and O(1).
    • For a max-heap, push negated values; for ties, push tuples such as `(-count, word)`.
    • Top-k with a size-k min-heap is O(n log k) and works on streams.
    • Name `heapq.nlargest` in an interview, but be ready to build it.
  10. Break a problem into overlapping subproblems and remember each answer once.

    • DP solves each overlapping subproblem once and remembers it: exponential recursion becomes polynomial.
    • Recipe: define the state, the transition, the base case, the order and where the answer lives.
    • Top-down is recursion plus a memo; bottom-up fills a table in order. Both give the same answer.
    • Greedy can fail where DP works: coins `[1, 5, 6]` for 10.
01Do I need to know Python already?

You should be comfortable with loops, functions, lists and dictionaries. If not, start with the Python for Beginners course first.

02Can I use another language in the interview?

Usually yes. The patterns are the same in any language. Python is used here because it is short to read and write.

03How many problems should I practice?

Quality beats quantity. Understand each pattern well enough to explain it and solve a new variant, then keep practising across patterns.

04Does this cover system design?

No. It covers the algorithms and data structures round. System design is a separate skill.

05Are the problems copied from real interviews?

No. Every problem is written for this course and follows the common patterns.

Study it properly, free

Start the course in BiliMind and it's yours: 69 questions marked as you go, 41 flashcards on spaced review, a plan around your week, and an assistant that can change any lesson.

Facts checked against: Python docs: heapq, Python docs: collections (deque), Python docs: bisect, Python wiki: TimeComplexity.

See the roadmap for this subject