This repo consists of my own categorization of coding interview questions. I collected these questions from multiple sources, primarily LeetCode and books such as Elements of Programming Interviews, Cracking the Coding Interview, and Beyond Cracking the Coding Interview. I like to group the questions under a prominent theme and break them down further into data structures and common techniques.
I organize the questions in order, meaning you need to solve them in the order presented, because subsequent questions are built upon the answers to those that come before. For some patterns that utilize the same data structure, such as trees, I also intentionally organize them in order (e.g., you need to know how to traverse a tree before learning how to search for a specific value in the tree). This approach helps me reinforce my understanding and notice repeated mistakes I make under the same theme.
Reversal pattern often asks you to change the order of items or swap them in different data structures.
- 344. Reverse String
- 541. Reverse String II
- 557. Reverse Words in a String III
- 345. Reverse Vowels of a String
- 151. Reverse Words in a String
Common pitfalls I made so you don't have to:
- Forgot to convert a string into a list before performing the swap. Because a string is immutable, we cannot modify it directly.
- Forgot to use a while loop for the swapping logic, but used an
if
statement, so the swapping only occurs once. - Once in a while, did not handle the index and the bounds of the index well, so got the error of list index out of range.
- 206. Reverse Linked List
- 92. Reverse Linked List II
- 25. Reverse Nodes in k-Group
- 2074. Reverse Nodes in Even Length Groups
- 24. Swap Nodes in Pairs
- 1721. Swapping Nodes in a Linked List
Common pitfalls I made so you don't have to:
- The trickiest part of reversing a linked list is to keep track of the reassignment of the head/left nodes and right/end nodes. The best solution I found for this problem is to visualise or draw every step for the first few problems you do, instead of just half-dry-running the example. You must internalize the reassignment mechanism before you can proceed to more complex problems.
- Carefully read the problem to see whether it asks you to swap the values only or to change the pointers/references of the nodes.
- 102. Binary Tree Level Order Traversal
- 429. N-ary Tree Level Order Traversal
- 103. Binary Tree Zigzag Level Order Traversal
- 107. Binary Tree Level Order Traversal II
- 144. Binary Tree Preorder Traversal
- 94. Binary Tree Inorder Traversal
- 145. Binary Tree Postorder Traversal
- 589. N-ary Tree Preorder Traversal
- 590. N-ary Tree Postorder Traversal
- 700. Search in a Binary Search Tree
- 270. Closest Binary Search Tree Value
- 272. Closest Binary Search Tree Value II
- 2476. Closest Nodes Queries in a Binary Search Tree
The process of generating or listing all possible solutions to an optimization problem that a DP algorithm solves, rather than just finding the optimal one.
This list consists of my favourite problems, problems that made me say "Wow, I've never thought of that!" when I looked at the solution and those that have some practical applications