Top LeetCode Patterns for FAANG Coding Interviews
Tags: programming, career, leetcode, python
Published: 2022-07-29 11:29:00

Preparing for coding interviews can be made easier by focusing on coding patterns. Every software engineer should learn coding patterns such as Sliding Window, Two Pointers, Two Heaps, etc. By doing so, software engineers will be able to develop the skill of “mapping a new problem to an existing one.” In this post, we will learn which coding patterns have the highest return on investment for software engineers.

[Grokking the Coding Interview](https://www.designgurus.io/course/grokking-the-coding-interview) came up with a list of 18 patterns for coding questions based on the similarities in the techniques needed to solve them. The course’s idea is to teach famous coding patterns so that once someone is familiar with a pattern, they will be able to solve dozens of problems with it.

## LeetCode Problems Distribution
LeetCode (LC), being the largest repository of coding problems, contains more than 2k+ questions. Each question on LC can be tagged with one or more topics. These topics are either data structures like Array, HashTable, Tree, etc., or algorithmic techniques like Greedy, Divide and Conquer, Sorting, etc., or coding patterns like Sliding Window, Depth First Search, Topological Sort, etc. Here is the topic distribution for LC questions:

![LeetCode Topic Distribution](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fizcdcifvso1s9ysh0pu.png)


The top topic is Array with 1142 problems, followed by String with 549 problems, and so on. Let’s take a closer look at each category of topics, namely Data Structures, Algorithms, and Coding Patterns.

## Top Data Structures with Best ROI
Here are the top Data Structures with the highest return on investment:

1. Array (1142 problems)
2. String (549)
3. Hash Table (392)
4. Tree (191)
5. Matrix (171)
6. Stack (128)
7. Heap or Priority Queue (107)
8. Graph (102)
9. Linked List (69)
10. Trie (44)

## Top Algorithmic Techniques with Best ROI
Here are the top algorithmic techniques with the highest return on investment:

1. Dynamic Programming (383)
2. Sorting (253)
3. Greedy (248)
4. Binary Search (186)
5. Backtracking (91)
6. Recursion (44)
7. Divide and Conquer (38)

## Top Coding Patterns with Best ROI
Here are the top coding patterns with the highest return on investment:

1. Depth First Search (250)
2. Breadth First Search(198)
3. Binary Search (186)
4. Two Pointers (147)
5. Sliding Window (72)
6. Monotonic Stack (44)
7. Union Find (63)
8. Memoization (32)
9. Topological Sort (28)
10. Segment Tree (27)

## Best Coding Patterns with Highest ROI
Combining all categories from the above data, here is the list of best coding patterns/techniques with the highest ROI:

**1. [Two Pointers](https://designgurus.org/path-player?courseid=grokking-the-coding-interview&unit=grokking-the-coding-interview_1628743404181_0Unit) (Arrays, Strings, [Fast & Slow Pointer](https://designgurus.org/path-player?courseid=grokking-the-coding-interview&unit=grokking-the-coding-interview_1628743539397_12Unit))**
This pattern covers a huge set of questions related to Arrays and Strings, which are the highest tagged data structures. Fast & Slow Pointer can be easily understood as a variation of the Two Pointers pattern.

**2. [Sliding Window](https://designgurus.org/path-player?courseid=grokking-the-coding-interview&unit=grokking-the-coding-interview_1627871350324_0Unit) (Arrays, Strings, Hash Tables)**
Sliding Window covers most of the problems related to top data structures like Arrays, Strings, and HashTables.

**3. [Tree and Graph Depth First Search](https://designgurus.org/path-player?courseid=grokking-the-coding-interview&unit=grokking-the-coding-interview_1628743917257_53Unit) ([Matrix Traversal](https://designgurus.org/path-player?courseid=grokking-the-coding-interview&unit=grokking-the-coding-interview_62d7d2809d90bUnit))**
Most Trees and Graphs problems can be solved using Depth First Search (DFS). Matrix Traversal, which is also DFS based pattern, covers most of the matrix-related problems.

**4. [Tree and Graph Breadth First Search](https://designgurus.org/path-player?courseid=grokking-the-coding-interview&unit=grokking-the-coding-interview_1628743839113_43Unit) (Queue, [Subsets](https://designgurus.org/path-player?courseid=grokking-the-coding-interview&unit=grokking-the-coding-interview_1628744031780_66Unit), [Matrix Traversal](https://designgurus.org/path-player?courseid=grokking-the-coding-interview&unit=grokking-the-coding-interview_62d7d2809d90bUnit), [Topological Sort](https://designgurus.org/path-player?courseid=grokking-the-coding-interview&unit=grokking-the-coding-interview_1628744523199_120Unit))**
Breadth First Search (BFS) is a very handy pattern. BFS’s patterns like Subsets, Matrix Traversal, and Topological Sort cover a good number of problems.

**5. [Binary Search](https://designgurus.org/path-player?courseid=grokking-the-coding-interview&unit=grokking-the-coding-interview_1628744125571_76Unit) (Arrays)**
Binary Search and its variants are used to solve a huge number of coding questions.

**6. [Interval Merge](https://designgurus.org/path-player?courseid=grokking-the-coding-interview&unit=grokking-the-coding-interview_1628743615987_20Unit)**
Although there are not many problems related to Interval Merge, these problems frequently appear in coding interviews.

**7. Recursion/Backtracking**
Backtracking and recursion are used to solve a wide range of problems. Mastering these techniques is highly recommended.

## Conclusion
Most programming interviews include LeetCode-type questions. Software engineers practice such coding problems before interviews. The highest return on investment is achieved by preparing smartly and focusing on the problem patterns. You can learn more about these patterns and related problems in [Grokking the Coding Interview](https://www.designgurus.io/course/grokking-the-coding-interview) and [Grokking Dynamic Programming for Coding Interviews](https://designgurus.io/course/grokking-dynamic-programming).

Preparing for system design interviews, see this: [The Complete Guide to Ace the System Design Interview](https://designgurus.io/blog/complete-guide-sys-design)