Coding Interview Patterns in Rust
My solutions in Rust for all the problems in the book : ISBN-10: 1736049135
- Including Bonus.pdf
- Every chapter and every problem are listed at the bottom of this page: All chapters and problems
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 thebonus.pdf - A copy of
bonus.pdfis available in the/assetsdirectory
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 :
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.
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 :
- In a local project on your PC. Read this page where I share my setup on Windows 11.
- A better solution is to start by using the Rust Playground.
- In both cases, you may have to uncomment the line :
fn main(){
This may help
- The page where I explain how to Use Rust in Jupyter Notebooks on Windows
- My repo with code in Python.
- In the README I explain why I believe it is better to use Jupyter Notebooks in this learning context.
- The repo of the book
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.
- Chapter 01 - Two Pointers
- Chapter 02 - Hash Maps and Hash Sets
- Chapter 03 - Linked Lists
- Chapter 04 - Fast and Slow Pointers
- Chapter 05 - Sliding Windows
- Chapter 06 - Binary Search
- Chapter 07 - Stacks
- Chapter 08 - Heaps
- Chapter 09 - Intervals
- Chapter 10 - Prefix Sums
- Chapter 11 - Trees
- p189 - Introduction
- p193 - Invert Binary Tree
- p197 - Balanced Binary Tree Validation
- p200 - Rightmost Nodes of a Binary Tree
- p204 - Widest Binary Tree Level
- p207 - Binary Search Tree Validation
- p212 - Lowest Common Ancestor
- p216 - Build Binary Tree from Preorder and Inorder Traversals
- p221 - Maximum Sum of a Continuous Path in a Binary Tree
- bonus087 - Binary Tree Symetry
- bonus091 - Binary Tree Columns
- bonus096 - Kth Smallest Number in a Binary Search Tree
- bonus101 - Serialize and Deserialize a Binary Tree
- Chapter 12 - Tries
- Chapter 13 - Graphs
- Chapter 14 - Backtracking
- Chapter 15 - Dynamic Programming
- Chapter 16 - Greedy
- Chapter 17 - Sort and Search
- Chapter 18 - Bit Manipulation
- Chapter 19 - Math and Geometry