To LeetCode or not to LeetCode? What if you don't want to practice 100s of coding questions before your next coding interview? There is a part of me that dislikes coding interviews, primarily because it requires me to spend a lot of time preparing for coding questions. Moreover, during an interview, I have to present a reasonable (if not optimal) solution to someone who is evaluating me, something I don't have to deal with in my everyday life as a software engineer. Having said that, I do love algorithms and solving coding problems. It is a fun activity for me, it gives me good mental exercise, and I love to spend time on it. In this post, I would like to share some of my learnings and the techniques that I've developed over time which makes preparing for coding interviews an exciting and fun activity. A little about me; my software engineering career spans around 20 years, in which I've switched jobs five times. I've given around 30 interview loops containing 120+ interviews. I have some experience sitting on the other side of the table too. I've taken 300+ coding interviews and 200+ system design interviews. Background If you are looking to switch jobs and preparing for coding interviews, you will definitely know . It is probably the biggest online repository for coding interview questions and also contains a vibrant community to discuss algorithms with other fellow engineers. Whenever I'm free, I love spending time on LeetCode, trying to solve a new coding question, or learning from other smart solutions that people have developed. LeetCode Problems with LeetCode What is an ample amount of questions one should go through before considering themselves prepared for their coding interview? I would love to see a streamlined process that can guide me and teach me enough algorithmic techniques to feel confident for the interview. Being a lazy person myself, I wouldn't say I like to go through 500+ questions. One of the biggest challenges with LeetCode is that it lacks organization; it has a huge set of coding problems, and one feels lost on where to start or what to focus on. The Solution One technique that people often follow is to solve questions related to the same data structure; for example, focusing on questions related to Arrays, then LinkedList, HashMap, Heap, Tree, or Trie, etc. Although this does provide some organization, it still lacks coherence. For example, many questions can be solved using HashMaps but still require different algorithmic techniques. I would love to see question sets that follow not only the same data structure but also similar algorithmic techniques. The best thing I came across was the problem-solving patterns like , , or , etc. Following these patterns helped me nurture my ability to map a new problem to an already known problem. This not only made this whole coding-interview-preparation process fun but also a lot more organized. Sliding Window Fast and Slow Pointers Topological Sort I have gathered around 25 of these coding problem patterns, which I believe can help anyone learn these beautiful algorithmic techniques and make a real difference in the coding interviews. The idea behind these patterns is, once you're familiar with a pattern, you'll be able to solve dozens of problems with it. For a detailed discussion of these patterns and related problems with solutions, take a look at Grokking the Coding Interview . So, without further ado, let me list all these patterns: Sliding Window Two Pointers Fast & Slow Pointers Merge Intervals Cyclic Sort In-place Reversal of a LinkedList Tree Breadth-First Search Tree Depth First Search Two Heaps Subsets Modified Binary Search Bitwise XOR Top 'K' Elements K-way Merge 0/1 Knapsack Unbounded Knapsack Fibonacci Numbers Palindromic Subsequence Longest Common Substring Topological Sort Trie Traversal Number of Island Trial & Error Union Find Unique Paths Following is a small intro of each of these patterns with sample problems: 1. Sliding Window : This algorithmic technique is used when we need to handle the input data in specific window size. Usage Sample Problems: Longest Substring with K Distinct Characters Fruits into Baskets Permutation in a String 2. Two Pointers : In this technique, we use two pointers to iterate the input data. Generally, both pointers move in the opposite direction at a constant interval. Usage Sample Problems: Squaring a Sorted Array Dutch National Flag Problem Minimum Window Sort 3. Fast & Slow Pointers : Also known as Hare & Tortoise algorithm. In this technique, we use two pointers that traverse the input data at a different speed. Usage Sample Problems: Middle of the LinkedList Happy Number Cycle in a Circular Array 4. Merge Intervals : This technique is used to deal with overlapping intervals. Given two intervals ('a' and 'b'), there will be six different ways the two intervals can relate to each other: Usage Sample Problems: Intervals Intersection Conflicting Appointments Minimum Meeting Rooms 5. Cyclic Sort : Use this technique to solve array problems where the input data lies within a fixed range. Usage Sample Problems: Find all Missing Numbers Find all Duplicate Numbers Find the First K Missing Positive Numbers 6. In-place Reversal of a LinkedList : This technique describes an efficient way to reverse the links between a set of nodes of a LinkedList. Often, the constraint is that we need to do this in-place, i.e., using the existing node objects and without using extra memory. Usage Sample Problems: Reverse every K-element Sub-list Rotate a LinkedList 7. Tree Breadth-First Search : As the name suggests, this technique is used to solve problems involving traversing trees in a breadth-first search manner. Usage Sample Problems: Binary Tree Level Order Traversal Minimum Depth of a Binary Tree Connect Level Order Siblings 8. Tree Depth First Search : As the name suggests, this technique is used to solve problems involving traversing trees in depth-first search manner. Usage Sample Problems: Path With Given Sequence Count Paths for a Sum 9. Two Heaps In many problems, where we are given a set of elements such that we can divide them into two parts. We are interested in knowing the smallest element in one part and the biggest element in the other part. As the name suggests, this technique uses a Min-Heap to find the smallest element and a Max-Heap to find the biggest element. Usage: Sample Problems: Find the Median of a Number Stream Next Interval 10. Subsets Use this technique when the problem asks to deal with permutations or combinations of a set of elements. Usage: Sample Problems: String Permutations by changing case Unique Generalized Abbreviations 11. Modified Binary Search Use this technique to search a sorted set of elements efficiently. Usage: Sample Problems: Ceiling of a Number Bitonic Array Maximum 12. Bitwise XOR This technique uses the XOR operator to manipulate bits to solve problems. Usage: Sample Problems: Two Single Numbers Flip and Invert an Image 13. Top 'K' Elements This technique is used to find top/smallest/frequently occurring 'K' elements in a set. Usage: Sample Problems: 'K' Closest Points to the Origin Maximum Distinct Elements 14. K-way Merge This technique helps us solve problems that involve a list of sorted arrays. Usage: Sample Problems: Kth Smallest Number in M Sorted Lists Kth Smallest Number in a Sorted Matrix 15. 0/1 Knapsack This technique is used to solve optimization problems. Use this technique to select elements that give maximum profit from a given set with a limitation on capacity and that each element can only be picked once. Usage: Sample Problems: Equal Subset Sum Partition Minimum Subset Sum Difference 16. Unbounded Knapsack Use this technique to select elements that give maximum profit from a given set with a limitation on capacity and that each element can be picked multiple times. Usage: Sample Problems: Rod Cutting Coin Change 17. Fibonacci Numbers Use this technique to solve problems that follow the Fibonacci numbers sequence, i.e., every subsequent number is calculated from the last few numbers. Usage: Sample Problems: Staircase House Thief 18. Palindromic Subsequence This technique is used to solve optimization problems related to palindromic sequences or strings. Usage: Sample Problems: Longest Palindromic Subsequence Minimum Deletions in a String to make it a Palindrome 19. Longest Common Substring Use this technique to find the optimal part of a string/sequence or set of strings/sequences. Usage: Sample Problems: Maximum Sum Increasing Subsequence Edit Distance 20. Topological Sort Use this technique to find a linear ordering of elements that have dependencies on each other. Usage: Sample Problems: Tasks Scheduling Alien Dictionary 21. Trie Traversal Use this technique that involves creating or traversing of Trie data structure. Usage: Sample Problems: Longest Word in Dictionary Palindrome Pairs 22. Number of Island Use this technique to traverse a two-dimensional array and find a set of connected elements. Usage: Sample Problems: Number of Distinct Islands Maximum Area of Island 23. Trial & Error Use this technique to traverse an array to find a required optimal element. The traversal process runs in a trial & error manner. Usage: Sample Problems: Find Kth Smallest Pair Distance Minimize Max Distance to Gas Station 24. Union Find Use this technique to solve problems that require maintaining a given set of elements partitioned into multiple non-overlapping subsets. Usage: Sample Problems: Number of Provinces Bipartite Graph 25. Unique Paths Use this technique to find different/optimal ways to traverse a multi-dimensional array. Usage: Sample Problems: Find Unique Paths Dungeon Game Conclusion Like it or not, LeetCode-type questions are a part of almost every programming interview, so every software developer should practice them before an interview. Their only option is to prepare smartly and learn problem-solving by focusing on the underlying problem patterns. Learn more about these patterns and sample problems in and . Grokking the Coding Interview Grokking Dynamic Programming for Coding Interviews Check for some interesting courses on Coding and Design Gurus System Design interviews. First Published here