0% found this document useful (0 votes)
66 views2 pages

DSA Pattern Recognizer Cheatsheet

Uploaded by

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

DSA Pattern Recognizer Cheatsheet

Uploaded by

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

■ DSA Pattern Recognizer & Cheatsheet ■

1. Arrays
Problem Type Common Patterns / Solutions

Sorted Array Binary Search, Two Pointers, Sliding Window


Unsorted Array HashMap/Set for lookups, Sorting + Two Pointers
Prefix/Suffix Problems Prefix Sum, Difference Array, Kadane’s Algorithm
Subarray Problems Sliding Window, Prefix Sum + HashMap, Kadane’s
Rotation/Shift Problems Reverse Method, Modulo Indexing

2. Strings
Problem Type Common Patterns / Solutions

Palindrome Problems Two Pointers, Expand Around Center, DP


Substring Problems Sliding Window, Hashing (Rabin-Karp), KMP
Anagrams Sorting + Comparison, Frequency Counter, Sliding Window
Pattern Matching KMP, Z-Algorithm, Rabin-Karp
Longest/Common Subsequence Dynamic Programming, LCS Table

3. Linked List
Problem Type Common Patterns / Solutions

Cycle Detection Floyd’s Cycle Detection (Tortoise & Hare)


Reversal Iterative Reversal, Recursive Reversal
Middle Node Slow & Fast Pointer
Merging Two Pointer Merge Technique
Intersection HashSet, Length Difference Method

4. Stack & Queue


Problem Type Common Patterns / Solutions

Balanced Parentheses Stack Matching


Next Greater/Smaller Element Monotonic Stack
Sliding Window Max/Min Deque
LRU Cache HashMap + Doubly Linked List
Evaluate Expressions Stack for Postfix/Prefix
5. Heaps
Problem Type Common Patterns / Solutions

Top K Problems Min Heap/Max Heap, QuickSelect


Median of Stream Two Heaps
Merge K Sorted Lists Min Heap
Heap Sort Heapify + Extract Max/Min
Frequency Problems Heap + HashMap

6. Recursion & Backtracking


Problem Type Common Patterns / Solutions

Subsets/Combinations Recursion Tree, Backtracking


Permutations DFS + Swapping, Backtracking
N-Queens / Sudoku Backtracking with Constraints
Rat in a Maze / Pathfinding DFS + Backtracking
Word Search Problems DFS with Visited Set

7. Binary Search
Problem Type Common Patterns / Solutions

Find Element in Sorted Array Standard Binary Search


First/Last Occurrence Modified Binary Search
Search in Rotated Array Binary Search with Pivot
Peak Element Binary Search Variant
Binary Search on Answer Optimization Problems like Min Time, Min Capacity

You might also like