DSA Patterns for Coding Interviews: Complete LeetCode Roadmap (Beginner to Advanced)
Preparing for coding interviews can feel overwhelming because there are thousands of problems available on LeetCode. Many candidates spend months solving random questions but still struggle when faced with a new problem during an interview. The reason is simple: successful interview preparation is not about memorizing solutions. it is about recognizing patterns.
Most coding interview questions asked by companies such as Google, Amazon, Meta, Microsoft, Uber, Airbnb, LinkedIn, Atlassian and Stripe are variations of a relatively small set of algorithmic patterns. Once you learn how these patterns work and when they should be applied, solving unseen problems becomes significantly easier.
This guide organizes LeetCode problems by patterns instead of topics alone. For each pattern, you'll learn what it is, when to use it, common interview signals and representative problems to practice.
TOPIC 1: BASICS
Basic programming concepts form the foundation of every advanced algorithm. Strong fundamentals help you write bug-free code and quickly identify edge cases during interviews.
Pattern: Conditional Logic (If-Else)
Conditional statements allow programs to make decisions based on different inputs and states. Although this pattern appears simple, many interview questions test how well candidates handle boundary conditions, overlapping rules and special cases.
Interviewers often use conditional problems to evaluate coding discipline, readability and attention to detail. These questions are particularly useful in screening rounds because they reveal whether a candidate can translate business rules into working code.
Problems
- Fizz Buzz π’ Easy
- Palindrome Number π’ Easy
- Number of Steps to Reduce a Number to Zero π’ Easy
Pattern: Loops and Iteration
Loop-based problems teach you how to process collections, accumulate values and repeatedly execute operations efficiently. Mastering iteration is critical because almost every algorithm relies on traversing arrays, strings, linked lists or trees.
Many beginners focus on solving problems but overlook writing efficient loops. Interviewers expect candidates to understand iteration complexity and identify opportunities to avoid unnecessary nested loops.
Problems
- Running Sum of 1d Array π’ Easy
- Find Numbers with Even Number of Digits π’ Easy
- Richest Customer Wealth π’ Easy
Pattern: Simulation and Implementation
Simulation problems require implementing a set of rules exactly as described. These questions may not involve advanced algorithms, but they heavily test problem comprehension and coding accuracy.
A common mistake is jumping into coding before understanding all requirements. Successful candidates carefully model the system, process each operation step-by-step and handle edge cases systematically.
Problems
- Baseball Game π’ Easy
- Robot Return to Origin π’ Easy
Pattern: Mathematics
Mathematical problems often involve number theory, digit manipulation, modular arithmetic or mathematical observations. The key skill here is recognizing patterns that allow you to avoid brute-force computation.
Many interview candidates incorrectly assume that these questions require advanced mathematics. In reality, most solutions depend on simple observations that reduce complexity dramatically.
Problems
- Reverse Integer π‘ Medium
- Plus One π’ Easy
- Add Digits π’ Easy
TOPIC 2: ARRAYS
Arrays are by far the most frequently tested data structure in coding interviews. They serve as the foundation for many advanced concepts such as sliding window, two pointers, prefix sums, binary search and dynamic programming.
Candidates who master array patterns usually gain a significant advantage because these patterns appear repeatedly across interview rounds.
Pattern: Array Fundamentals
Array fundamentals involve element manipulation, rotation, insertion, deletion and in-place transformations. These questions help interviewers evaluate your understanding of indexing, memory efficiency and traversal strategies.
A major focus is reducing extra space usage and finding optimal solutions instead of relying on auxiliary arrays.
Problems
- Rotate Array π‘ Medium
- Move Zeroes π’ Easy
- Remove Duplicates from Sorted Array π’ Easy
Pattern: Prefix Sum
Prefix sums are one of the most important interview patterns because they transform repeated range calculations into constant-time operations. Instead of recalculating sums repeatedly, we precompute cumulative information.
Whenever you see terms like "subarray sum", "range query", "continuous sequence" or "count subarrays", prefix sums should immediately come to mind. This technique often converts O(nΒ²) solutions into O(n).
Problems
- Continuous Subarray Sum π‘ Medium
- Subarray Sum Equals K π‘ Medium
- Product of Array Except Self π‘ Medium
- Subarray Sums Divisible by K π‘ Medium
- Range Sum Query 2D - Immutable π‘ Medium
Pattern: Kadane's Algorithm
Kadane's Algorithm is used to solve maximum or minimum contiguous subarray problems efficiently. Instead of evaluating every possible subarray, it dynamically decides whether to extend the current segment or start a new one.
This pattern appears surprisingly often in interviews, particularly when dealing with profits, gains, losses or optimization over continuous ranges.
Problems
- Maximum Subarray π‘ Medium
- Maximum Product Subarray π‘ Medium
- Best Time to Buy and Sell Stock π’ Easy
Pattern: Intervals
Interval problems deal with overlapping ranges, scheduling, meeting rooms, reservations and timelines. The most common strategy is sorting intervals and then processing them sequentially.
Candidates often miss the sorting observation and attempt unnecessarily complex approaches. Learning interval patterns can unlock many scheduling and resource allocation problems.
Problems
- Merge Intervals π‘ Medium
- Insert Interval π‘ Medium
- Non-overlapping Intervals π‘ Medium
Pattern: Hashing
Hash maps and hash sets provide average O(1) lookups, making them one of the most powerful tools in interview problem solving. Many brute-force solutions can be optimized dramatically by storing previously seen information.
Whenever you encounter duplicate detection, frequency counting, complement lookup or grouping problems, hashing is often the optimal solution.
Problems
- Two Sum π’ Easy
- Majority Element π’ Easy
- Majority Element II π‘ Medium
- Top K Frequent Elements π‘ Medium
- Valid Anagram π’ Easy
- Group Anagrams π‘ Medium
- Longest Consecutive Sequence π‘ Medium
TOPIC 3: STRINGS
String problems are extremely common because they test both algorithmic thinking and implementation accuracy. Interviewers often use string questions to evaluate how well candidates handle indexing, character processing and edge cases.
Unlike arrays, strings introduce additional challenges such as encoding, pattern matching and substring manipulation.
Pattern: String Fundamentals
String fundamentals involve reversing, parsing, transforming, compressing and converting textual data. These questions establish the foundation required for more advanced string algorithms.
Strong understanding of string manipulation significantly improves performance in coding interviews because many real-world systems process textual information.
Problems
- Reverse String π’ Easy
- Reverse Words in a String III π’ Easy
- Roman to Integer π’ Easy
- String Compression π‘ Medium
Pattern: Frequency Counting and Hashing
Frequency counting is one of the most effective techniques for string analysis. By maintaining character counts, we can efficiently detect anagrams, similarities and transformations.
These problems frequently appear in interviews because they combine hash maps with string traversal, making them excellent tests of practical coding ability.
Problems
- Isomorphic Strings π’ Easy
- Bulls and Cows π‘ Medium
Pattern: Palindromes
Palindrome problems revolve around symmetry. The most common techniques include two pointers, expand-around-center and dynamic programming.
These questions are highly popular among interviewers because they can be solved at multiple complexity levels, allowing evaluation of optimization skills.
Problems
- Valid Palindrome π’ Easy
- Longest Palindromic Substring π‘ Medium
- Palindromic Substrings π‘ Medium
- Palindrome Partitioning π‘ Medium
TOPIC 4: RECURSION & BACKTRACKING
Recursion allows problems to be broken into smaller instances of themselves. Backtracking extends recursion by systematically exploring all possibilities while pruning invalid paths.
These patterns are particularly important for Google, Meta and Microsoft interviews because they test a candidate's ability to reason about state spaces.
Pattern: Backtracking
Backtracking follows the "Choose β Explore β Undo" philosophy. At each decision point, we try a choice, explore its consequences and revert before trying another option.
This pattern is ideal for generating combinations, permutations, subsets, arrangements and solving constraint satisfaction problems.
Problems
- Subsets π‘ Medium
- Subsets II π‘ Medium
- Permutations π‘ Medium
- Permutations II π‘ Medium
- Combination Sum π‘ Medium
- Combination Sum II π‘ Medium
- N-Queens π΄ Hard
- Sudoku Solver π΄ Hard
TOPIC 5: TWO POINTERS
Two Pointers is one of the highest-return-on-investment patterns in coding interviews. The core idea is to maintain two indices that move through the data structure in a controlled manner. Instead of using nested loops and checking every possible combination, two pointers help reduce time complexity from O(nΒ²) to O(n).
This pattern is especially common in array and string problems. Interviewers love it because it tests optimization skills and demonstrates whether candidates can identify opportunities to eliminate unnecessary work.
Pattern: Opposite Direction Pointers
In this variation, one pointer starts from the left side and another starts from the right side. Based on specific conditions, pointers move inward until they meet.
This technique is commonly used when the input is sorted or when we need to evaluate pairs of elements efficiently. Many brute-force pair-searching problems can be optimized dramatically using this approach.
Recognition Signals
- Sorted arrays
- Pair sum problems
- Maximum area problems
- Palindrome verification
- Water trapping questions
Common Mistakes
- Forgetting to move pointers correctly
- Missing duplicate handling
- Using nested loops unnecessarily
Problems
- Two Sum II - Input Array Is Sorted π‘ Medium
- Container With Most Water π‘ Medium
- Trapping Rain Water π΄ Hard
Pattern: Merge Two Sorted Sequences
Many interview problems involve combining two sorted structures efficiently. Instead of repeatedly searching for the next element, we compare both pointers and move the smaller one.
This pattern forms the foundation of Merge Sort and appears frequently in interval and linked list questions.
Problems
- Merge Sorted Array π’ Easy
- Interval List Intersections π‘ Medium
Pattern: Fixed Element + Two Pointers
These problems usually require finding triplets or quadruplets that satisfy a condition. The common strategy is fixing one element and applying the two-pointer technique on the remaining range.
This pattern is heavily tested because it demonstrates how candidates generalize optimization techniques.
Problems
- 3Sum π‘ Medium
- 3Sum Closest π‘ Medium
- 4Sum π‘ Medium
TOPIC 6: SLIDING WINDOW
Sliding Window is arguably the most important interview pattern after hashing. It is used to solve contiguous subarray and substring problems efficiently.
Instead of recalculating information for every window, we incrementally update the current window as it expands or shrinks. This optimization often reduces complexity from O(nΒ²) to O(n).
Pattern: Fixed Size Window
A fixed-size sliding window maintains exactly K elements at all times. As the window moves forward, one element enters and another leaves.
This approach is useful for moving averages, rolling sums and fixed-length substring problems.
Problems
- Maximum Average Subarray I π’ Easy
- Number of Sub-Arrays of Size K and Average >= Threshold π‘ Medium
- Maximum Sum of Distinct Subarrays With Length K π‘ Medium
Pattern: Variable Size Window
Variable windows expand and contract dynamically based on constraints. This is one of the most frequently asked patterns in FAANG interviews.
Whenever you encounter phrases like "longest", "smallest", "at most K", "exactly K" or "continuous sequence", think about sliding windows.
Problems
- Longest Subarray of 1's After Deleting One Element π‘ Medium
- Max Consecutive Ones III π‘ Medium
- Fruit Into Baskets π‘ Medium
- Binary Subarrays With Sum π‘ Medium
- Count Number of Nice Subarrays π‘ Medium
- Subarray Product Less Than K π‘ Medium
- Subarrays With K Different Integers π΄ Hard
Pattern: Sliding Window on Strings
String-based sliding windows combine hashing and window management. These problems are extremely common in coding interviews because they test both algorithmic thinking and implementation skills.
Problems
- Maximum Number of Vowels in a Substring of Given Length π‘ Medium
- Longest Substring Without Repeating Characters π‘ Medium
- Longest Repeating Character Replacement π‘ Medium
- Find All Anagrams in a String π‘ Medium
- Minimum Window Substring π΄ Hard
TOPIC 7: STACKS & QUEUES
Stacks and queues are fundamental linear data structures used extensively in interviews. Many candidates underestimate them, but several hard problems become straightforward once the correct stack pattern is recognized.
Pattern: Monotonic Stack
A monotonic stack maintains elements in increasing or decreasing order. This allows us to efficiently find the next greater element, previous smaller element and various range-based answers.
Monotonic stacks are one of the most powerful interview techniques because they transform many O(nΒ²) problems into O(n).
Problems
- Next Greater Element I π’ Easy
- Next Greater Element II π‘ Medium
- Largest Rectangle in Histogram π΄ Hard
- Maximal Rectangle π΄ Hard
- Daily Temperatures π‘ Medium
- Sum of Subarray Minimums π‘ Medium
- Asteroid Collision π‘ Medium
TOPIC 8: LINKED LIST
Linked Lists test pointer manipulation skills and memory awareness. Unlike arrays, elements are connected through references, making traversal and modification different.
Many interviewers use linked list problems because they reveal how comfortable candidates are with low-level data structure operations.
Pattern: Fast and Slow Pointer
The tortoise-and-hare approach uses two pointers moving at different speeds. This elegant technique is useful for cycle detection and midpoint identification.
Problems
- Middle of the Linked List π’ Easy
- Linked List Cycle π’ Easy
- Linked List Cycle II π‘ Medium
Pattern: Reversal
Reversing linked lists is one of the most fundamental pointer manipulation exercises. Variations frequently appear in interviews.
Problems
- Reverse Linked List π’ Easy
- Reverse Linked List II π‘ Medium
- Reverse Nodes in k-Group π‘ Medium
TOPIC 9: TREES
Trees are among the most frequently asked advanced data structures in interviews. Mastering tree traversal and recursive thinking is essential for mid-level and senior software engineering roles.
Pattern: DFS Traversal
Depth First Search explores one branch completely before moving to another. DFS is naturally implemented using recursion or an explicit stack.
It is particularly useful for path-related calculations, subtree processing and hierarchical structures.
Problems
- Maximum Depth of Binary Tree π’ Easy
- Path Sum π’ Easy
- Sum Root to Leaf Numbers π‘ Medium
Pattern: BFS Traversal
Breadth First Search processes nodes level by level. BFS is typically implemented using queues and is useful for shortest-path and level-order problems.
Problems
- Binary Tree Level Order Traversal π‘ Medium
- Binary Tree Zigzag Level Order Traversal π‘ Medium
Pattern: Lowest Common Ancestor
LCA problems test tree recursion and ancestor relationships. They are among the most popular tree interview questions.
Problems
- Lowest Common Ancestor of a Binary Tree π‘ Medium
- Lowest Common Ancestor of a Binary Search Tree π‘ Medium
TOPIC 10: BINARY SEARCH
Binary Search is much more than searching in sorted arrays. It represents a way of thinking where we repeatedly eliminate half of the search space.
Many difficult interview questions become simple once candidates recognize that a monotonic property exists.
Pattern: Binary Search on Answer
Rather than searching for a value directly, we search for the optimal answer and verify whether it satisfies constraints.
This pattern is extremely common in modern interviews.
Problems
- Koko Eating Bananas π‘ Medium
- Capacity to Ship Packages Within D Days π‘ Medium
- Minimum Number of Days to Make m Bouquets π‘ Medium
TOPIC 11: HEAP (PRIORITY QUEUE)
Heaps allow efficient retrieval of the largest or smallest element. They are essential for scheduling systems, streaming data, ranking systems and resource allocation.
Pattern: Top K Elements
Whenever the problem asks for the K largest, K smallest or K most frequent items, heaps should be considered immediately.
Problems
- Kth Largest Element in an Array π‘ Medium
- Top K Frequent Words π‘ Medium
- K Closest Points to Origin π‘ Medium
Pattern: Two Heaps
Two heaps maintain balance between lower and upper halves of data. This technique is especially useful for streaming median problems.
Problems
- Find Median From Data Stream π΄ Hard
- Sliding Window Median π΄ Hard
TOPIC 12: GREEDY
Greedy algorithms make the best local decision at every step. While not every optimization problem is greedy, recognizing valid greedy opportunities is an important interview skill.
Pattern: Local Optimal Selection
The algorithm selects the best immediate choice hoping it contributes to a globally optimal solution.
Problems
- Jump Game π‘ Medium
- Jump Game II π‘ Medium
- Gas Station π‘ Medium
- Wiggle Subsequence π‘ Medium
TOPIC 13: DYNAMIC PROGRAMMING
Dynamic Programming is often considered the most challenging interview topic. It involves breaking a problem into overlapping subproblems and storing results to avoid repeated computation.
Strong DP skills are often a differentiator for senior candidates.
Pattern: 1D DP
The current state depends on one or more previous states. This is usually the easiest entry point into dynamic programming.
Problems
- Climbing Stairs π’ Easy
- House Robber π‘ Medium
- Coin Change π‘ Medium
Pattern: Longest Common Subsequence
LCS forms the basis for many string comparison problems and demonstrates classic DP state transitions.
Problems
- Longest Common Subsequence π‘ Medium
- Edit Distance π‘ Medium
- Distinct Subsequences π΄ Hard
Pattern: Longest Increasing Subsequence
LIS appears in scheduling, sequence optimization and ordering problems.
Problems
- Longest Increasing Subsequence π‘ Medium
- Russian Doll Envelopes π΄ Hard
TOPIC 14: GRAPHS
Graphs are among the most important topics for senior-level interviews. They model networks, social connections, routes, dependencies and distributed systems.
Pattern: Graph Traversal
Graph traversal using DFS or BFS helps determine reachability, connectivity and component structure.
Problems
- Number of Islands π‘ Medium
- Pacific Atlantic Water Flow π‘ Medium
- Making a Large Island π΄ Hard
Pattern: Topological Sorting
Topological sorting is used for dependency resolution and scheduling systems.
Problems
- Course Schedule π‘ Medium
- Course Schedule II π‘ Medium
- Find Eventual Safe States π‘ Medium
Pattern: Union Find
Union-Find efficiently manages connected components in dynamic graphs.
Problems
- Redundant Connection π‘ Medium
- Accounts Merge π‘ Medium
Pattern: Shortest Path
Shortest-path algorithms are fundamental for routing and network optimization.
Problems
- Network Delay Time π‘ Medium
- Path With Minimum Effort π‘ Medium
- Cheapest Flights Within K Stops π‘ Medium
TOPIC 15: TRIES
A Trie is a specialized tree structure designed for efficient prefix-based operations. It is heavily used in autocomplete systems, spell checkers, search engines and dictionaries.
While not as common as arrays or trees, Trie questions frequently appear in senior-level interviews because they test specialized data structure knowledge.
Pattern: Trie Implementation
Trie implementation focuses on insertion, search and prefix matching. Understanding node structures and traversal is essential.
Problems
- Implement Trie (Prefix Tree) π‘ Medium
Pattern: Prefix and Suffix Search
These problems extend Trie usage to advanced string indexing and querying systems.
Problems
- Longest Word in Dictionary π‘ Medium
- Longest Word in Dictionary through Deletion π‘ Medium
- Prefix and Suffix Search π΄ Hard
Pattern: XOR Trie
XOR Tries are specialized data structures used for bit manipulation problems. They allow efficient computation of maximum XOR values and range-based XOR queries.
These questions are often considered advanced and appear in high-level interviews.
Problems
- Maximum XOR of Two Numbers in an Array π‘ Medium
- Maximum XOR With an Element from Array π΄ Hard
- Count Pairs With XOR in a Range π΄ Hard
Final Learning Roadmap
If your goal is cracking FAANG/MANGA or top product companies, follow this sequence:
- Arrays & Hashing
- Two Pointers
- Sliding Window
- Binary Search
- Stack
- Linked List
- Trees
- Heap
- Greedy
- Graph Traversal
- Backtracking
- Dynamic Programming
- Trie
- Advanced Graphs
- Advanced Dynamic Programming
Following this order ensures that each new topic builds naturally on previously learned concepts, creating a strong foundation for solving complex interview problems.
