Coding Interview Patterns in Rust

My solutions in Rust for all the problems in the book : ISBN-10: 1736049135

Cover of the book Coding Interview Patterns, Nail Your Next Coding Interview, by Alex Xu and Shaun Gunawardane, ByteByteGo

How to

  • Everything is on Github
  • One directory per chapter (01_two_pointers … 19_math_and_geometry)
  • In the directories, the number at the beginning of the filename (e.g., 10_xxx.ipynb, 14_yyy.ipynb) corresponds to the page number in the book.
  • When the filename starts with bonus_ the exercice is one of the bonus.pdf
  • A copy of bonus.pdf is available in the /assets directory

In most notebooks

  • I do NOT provide any explanation about the algorithm. Read the book.
  • There is a recap of the challenge at the top of the page
  • Then you will find the following sections
    • The point : The tip or the trick to keep in mind about the puzzle
    • Complexity : Recap of the time & space complexities
    • TODO : This is mostly for me
    • About Rust :
      • You will find here a list of function calls, idioms, constructs…
      • There is no order, no priority
      • This is mostly for me since I’m learning Rust
      • I can repeat some items from one solution to another if I have trouble to keep them in mind
      • I usually confirm if the code of the cell has been executed in the Rust Playground
    • There may be cells with code that doesn’t work and I explain why
    • If there are multiple versions of the same solution
      • I explain the changes from one version to the next.
      • If it make sense, I highlight if one of the versions is my Preferred solution
      • When we come back to a notebook with several versions, the lime color makes it easy to find the one I prefer (this is purely personal)

This how the beginning of a notebook may look like :

Notebook header for Identify All Interval Overlaps: the point of the solution, its O(n+m) time complexity and notes about Rust

About the sample code

  • All code examples are self-contained. By that, I mean that, unlike the code presented in the book or in the associated GitHub repository, they are not just isolated functions; instead, each example includes a main() function where I demonstrate how to invoke the function and how to initialize any required data structures.
  • For example, in Chapter 11, which covers binary trees, all the solutions I provide create the trees used in the chapter and display the results. The idea is really that each piece of code should be self-sufficient and easy to run.
  • Yes, it results in more code, but I find it much more practical.
  • In most of the code examples, I try to keep the names of functions, variables… identical to those in the book.
Notebook cell Base implementation: the Rust pair_sum_sorted function with two pointers and its outputs [2, 3], [0, 2] and []

Click on the image above to enlarge it.

What if you don’t run Rust code in Jupyter Notebook

  • Shame on you 😁. Read this README.
  • You can copy and paste the code of the cell of interest either :
    1. In a local project on your PC. Read this page where I share my setup on Windows 11.
    2. A better solution is to start by using the Rust Playground.
    3. In both cases, you may have to uncomment the line : fn main(){

This may help

All chapters and problems

Each chapter page sums up the pattern in a few lines and links to its problems. In the book, regular problems come first, then the bonus ones.


Back to top

Published on: Jun 22 2025 at 03:00 PM | Last updated: Feb 25 1964 at 03:00 PM

Copyright © 1964-2026 - 40tude