0% found this document useful (0 votes)
3 views9 pages

DSA Interview Pattern Guide

The document is a guide outlining 20 core patterns for recognizing and solving LeetCode problems relevant to data structures and algorithms (DSA) interviews. Each pattern includes recognition signals and representative problems to help candidates master the underlying approaches for medium-level interview questions. It also provides a decision flow for quickly identifying applicable patterns based on the data structure involved.

Uploaded by

bhavik.dumore24
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

DSA Interview Pattern Guide

The document is a guide outlining 20 core patterns for recognizing and solving LeetCode problems relevant to data structures and algorithms (DSA) interviews. Each pattern includes recognition signals and representative problems to help candidates master the underlying approaches for medium-level interview questions. It also provides a decision flow for quickly identifying applicable patterns based on the data structure involved.

Uploaded by

bhavik.dumore24
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

DSA Interview Pattern Guide

20 Core Patterns for Recognizing LeetCode Problems


A reference guide mapping problem signals to the right algorithmic approach.

How to Use This Guide


Each pattern below lists the signals that suggest it applies, followed by representative LeetCode problems. Master these 20
patterns and solve 10–15 representative problems for each — you'll be able to recognize the underlying approach for most
medium-level interview questions within a minute.

1. Sliding Window
Recognition
● Is it an array or string?
● Am I looking for a subarray or substring?
● Does the question mention: longest, shortest, maximum, minimum, contiguous, fixed size K?
● If yes → Sliding Window

LeetCode Problems
Problem LC No.
Maximum Average Subarray I 643
Minimum Size Subarray Sum 209
Longest Substring Without Repeating Characters 3
Longest Repeating Character Replacement 424
Permutation in String 567
Minimum Window Substring 76
Sliding Window Maximum 239

2. Two Pointers
Recognition
● Array is sorted
● Two numbers whose sum = target
● Remove duplicates
● Move elements
● Compare from both ends
● Palindrome

LeetCode Problems
Problem LC No.
Two Sum II 167
Valid Palindrome 125
Remove Duplicates from Sorted Array 26
Container With Most Water 11
3Sum 15
4Sum 18

3. Fast & Slow Pointer


Recognition
● Usually Linked List
● Keywords: Cycle, Middle node, Happy Number, Circular array, Find duplicate

LeetCode Problems
Problem LC No.
Linked List Cycle 141
Linked List Cycle II 142
Middle of Linked List 876
Happy Number 202
Find Duplicate Number 287
Circular Array Loop 457

4. Merge Intervals
Recognition
● Input looks like [start, end]
● Need to: Merge, Overlap, Insert interval, Meeting rooms

LeetCode Problems
Problem LC No.
Merge Intervals 56
Insert Interval 57
Non-overlapping Intervals 435
Meeting Rooms II (Premium) 253
Problem LC No.
Minimum Number of Arrows 452

5. Cyclic Sort
Recognition
● Array contains numbers 1...N or 0...N
● Need: Missing number, Duplicate, Corrupt pair

LeetCode Problems
Problem LC No.
Missing Number 268
Find All Numbers Disappeared 448
Find All Duplicates 442
Set Mismatch 645
First Missing Positive 41

6. In-place Reversal of Linked List


Recognition
● Linked List
● Need: Reverse, Reverse between, Reverse every K nodes

LeetCode Problems
Problem LC No.
Reverse Linked List 206
Reverse Linked List II 92
Reverse Nodes in k Group 25
Swap Nodes in Pairs 24

7. Tree BFS
Recognition
● Need: Level Order, Zigzag, Right View, Minimum Depth
● Use a Queue
LeetCode Problems
Problem LC No.
Binary Tree Level Order 102
Zigzag Level Order 103
Average of Levels 637
Right Side View 199
Minimum Depth 111

8. Tree DFS
Recognition
● Need: Path, Root to Leaf, Maximum Path, Diameter
● Recursive

LeetCode Problems
Problem LC No.
Path Sum 112
Path Sum II 113
Binary Tree Maximum Path Sum 124
Diameter of Binary Tree 543
Sum Root to Leaf Numbers 129

9. Two Heaps
Recognition
● Keywords: Median, Running Median, Stream, Balance two halves

LeetCode Problems
Problem LC No.
Find Median from Data Stream 295
Sliding Window Median 480
IPO 502

10. Subsets / Backtracking


Recognition
● Question asks: Generate all, Every combination, Every permutation, Every subset
LeetCode Problems
Problem LC No.
Subsets 78
Subsets II 90
Permutations 46
Permutations II 47
Combination Sum 39
Combination Sum II 40
Letter Combinations 17
N Queens 51

11. Modified Binary Search


Recognition
● Sorted array
● Rotated array
● Need O(log n)
● Peak
● First/Last occurrence

LeetCode Problems
Problem LC No.
Binary Search 704
Search Insert Position 35
Search Rotated Array 33
Find Peak Element 162
Find First and Last Position 34
Koko Eating Bananas 875

12. Bitwise XOR


Recognition
● One unique number
● Missing number
● Every number appears twice
LeetCode Problems
Problem LC No.
Single Number 136
Single Number II 137
Single Number III 260
Missing Number 268

13. Top K Elements


Recognition
● Question literally says: Top K, K largest, K smallest, K closest, Most frequent

LeetCode Problems
Problem LC No.
Kth Largest Element 215
Top K Frequent Elements 347
K Closest Points 973
Sort Characters by Frequency 451

14. K-way Merge


Recognition
● Multiple sorted arrays or sorted linked lists
● Need merge

LeetCode Problems
Problem LC No.
Merge K Sorted Lists 23
Kth Smallest in Sorted Matrix 378
Find K Pairs with Smallest Sums 373

15. Topological Sort


Recognition
● Keywords: Prerequisite, Dependency, Scheduling, Build Order
● Directed Graph
LeetCode Problems
Problem LC No.
Course Schedule 207
Course Schedule II 210
Alien Dictionary (Premium) 269

16. 0/1 Knapsack


Recognition
● Every item: Take or Skip
● Use once

LeetCode Problems
Problem LC No.
Partition Equal Subset Sum 416
Target Sum 494
Ones and Zeroes 474
Last Stone Weight II 1049

17. Unbounded Knapsack


Recognition
● Items can be used again and again

LeetCode Problems
Problem LC No.
Coin Change 322
Coin Change II 518
Integer Break 343
Perfect Squares 279

18. Fibonacci DP
Recognition
● Current answer depends on dp[i-1] and dp[i-2]
LeetCode Problems
Problem LC No.
Fibonacci Number 509
Climbing Stairs 70
Min Cost Climbing Stairs 746
House Robber 198
House Robber II 213
Decode Ways 91

19. Monotonic Stack


Recognition
● Keywords: Next Greater, Previous Smaller, Daily Temperatures, Histogram, Stock Span

LeetCode Problems
Problem LC No.
Next Greater Element I 496
Daily Temperatures 739
Largest Rectangle in Histogram 84
Trapping Rain Water 42
Sum of Subarray Minimums 907

20. Graph (DFS/BFS / Union Find)


Recognition
● Need to: Traverse graph, Connected components, Islands, Shortest path, Clone graph

LeetCode Problems
Problem LC No.
Number of Islands 200
Clone Graph 133
Rotting Oranges 994
Word Ladder 127
Network Delay Time 743
Redundant Connection 684
Interview Pattern Recognition Flow
Use this decision flow to quickly narrow down which pattern applies once you've identified the data structure.

Array / String
● Contiguous? → Sliding Window
● Sorted? → Two Pointers / Binary Search
● Range 1..N? → Cyclic Sort
● Top K? → Heap
● Missing/Unique? → XOR
● Generate All? → Backtracking

Linked List
● Reverse? → Reverse Pattern
● Cycle/Middle? → Fast & Slow
● Merge? → Two Pointers / Heap

Tree
● Level Order? → BFS
● Path/Height? → DFS
● Ordered BST? → Binary Search

Graph
● Dependency? → Topological Sort
● Shortest Path? → BFS/Dijkstra
● Connected Components? → DFS/BFS/Union-Find

Dynamic Programming
● Take/Skip Once? → 0/1 Knapsack
● Unlimited Reuse? → Unbounded Knapsack
● Previous States? → Fibonacci DP
● Grid? → Grid DP

This list covers the vast majority of DSA interview questions on LeetCode.

You might also like