Coding Interview Patterns in Rust
My solutions in Rust for all the problems in the book : ISBN-10: 1736049135
- Including Bonus.pdf

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.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 :

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
Table of contents
- bonus005 - Shift zeros to the end
- bonus010 - Next lexicographical sequence
- bonus016 - Longest Chain of Consecutive Numbers
- bonus020 - Geometric Sequence Triplets
- bonus027 - Palindromic Linked List
- bonus031 - Flatten a Multi-Level Linked List
- bonus039 - Find the Median From Two Sorted Arrays
- bonus046 - Matrix Search
- bonus052 - Local Maxima
- bonus058 - Weighted Random Selection
- bonus064 - Repeated Removal of Adjacent Duplicates
- bonus067 - Implement a Queue Using Stacks
- bonus073 - Maximums of Sliding Window
- bonus080 - Sort K-Sorted Array
- bonus087 - Binary Tree Symetry
- bonus091 - Binary Tree Columns
- bonus096 - Kth Smallest Number in a Binary Search Tree
- bonus101 - Serialize and Deserialize a Binary Tree
- bonus108 - Shortest Path
- bonus116 - Connect the Dots
- bonus123 - Combinations of a Sum
- bonus128 - Phone Keypad Combinations
- bonus132 - Largest Square in a Matrix
- bonus141 - Dutch National Flag
- bonus145 - The Josephus Problem
- bonus149 - Triangle Numbers
- p010 - Pair Sum - Sorted
- p014 - Triplet Sum
- p020 - Is Palindrome Valid
- p024 - Largest Container
- p032 - Pair Sum - Unsorted
- p035 - Verify Sudoku Board
- p040 - Zero stripping
- p047 - Introduction
- p050 - Linked List Reversal
- p054 - Linked List Reversal Recursive
- p056 - Remove the kth Last Node From a Linked List
- p060 - Linked List Intersection
- p063 - LRU Cache
- p073 - Linked List Loop
- p077 - Linked List Midpoint
- p080 - Happy Number
- p086 - Substring Anagrams
- p090 - Longest Substring With Unique Characters
- p095 - Longest Uniform Substring After Replacements
- p101 - Introduction
- p105 - Find insertion index
- p110 - First and Last Occurence of a Number
- p116 - Cutting Wood
- p122 - Find the Target in a Rotated Sorted Array
- p130 - Valid Parenthesis Expression
- p132 - Next Largest Number to the Right
- p137 - Evaluate Expression
- p145 - K Most Frequent Strings
- p151 - Combine Sorted Linked Lists
- p155 - Median of an Integer Stream
- p161 - Merge Overlapping Intervals
- p166 - Identify All Interval Overlaps
- p170 - Largest Overlap of Interval
- p175 - Introduction
- p177 - Sum Between Range
- p180 - K-Sum Subarray
- p184 - Product Array Without Current Element
- 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
- p230 - Design a Trie
- p235 - Insert and Search Words with Wildcards
- p239 - Find All Words on a Board
- p247 - Introduction
- p250 - Graph Deep Copy
- p253 - Count Islands
- p258 - Matrix infection
- p264 - Bipartite Graph Validation
- p268 - Longest Increasing Path
- p272 - Shortest Transformation Sequence
- p280 - Merging Communities
- p287 - Prerequisites
- p298 - Find All Permutations
- p302 - Find All Subsets
- p305 - N Queens
- p311 - Climbing Stairs
- p316 - Minimum Coin Combination
- p321 - Matrix Pathways
- p325 - Neighborhood Burglary
- p329 - Longest Common Subsequence
- p334 - Longest Palindrome in a String
- p339 - Maximum Subarray Sum
- p345 - 0/1 Knapsack
- p354 - Jump to the End
- p358 - Gas Stations
- p364 - Candies
- p373 - Sort Linked List
- p379 - Sort Array
- p386 - Kth Largest Integer
- p393 - Introduction
- p396 - Hamming Weights of Integer
- p399 - Lonely Integer
- p401 - Swap Odd and Even Bits
- p406 - Spiral Traversal
- p411 - Reverse 32-Bit integer
- p415 - Maximum Collinear Points