DSA Patterns
Array
When preparing for Data Structures and Algorithms (DSA)💡 interviews, it's crucial to
master certain patterns🪜 that frequently arise in array problems📔.
1️ Sliding Window
Maximum sum subarray of size K
Longest substring without repeating characters
Count of anagrams in a string
2️ Two Pointers
✅ Key Problems:
Pair with a given sum
Merge two sorted arrays
Trapping Rain Water
3️ Kadane's Algorithm
✅ Key Problems:
Maximum Sum Subarray
Maximum Circular Subarray Sum
4️ Sorting-based Problems
✅ Key Problems:
Find triplets that sum to zero
Minimum platforms required for trains
Largest number formed from an array
5️ Binary Search on Arrays
✅ Key Problems:
Search in a rotated sorted array
Find the first and last position of an element
Median of two sorted arrays
6️ Prefix Sum & Difference Array
✅ Key Problems:
Subarray sum equals K
Range addition using difference array
Equilibrium index of an array
7️ Greedy Techniques
Used when making local optimal choices leads to global optimal solutions.
✅ Key Problems:
Follow me on Instagram, You Tube, and LinkedIn for more tech-related content
.
Maximum meetings in one room
Minimum number of platforms required
Candy distribution
8️ Matrix Variations (2️D Arrays)
2️D problems often include pathfinding and dynamic programming.
✅ Key Problems:
Spiral matrix traversal
Rotate a matrix by 90 degrees
Search in a 2️D matrix
9 Hashing in Arrays
Involves optimizing searches and pair/group detections.
✅ Key Problems:
Two-sum problem
Longest consecutive subsequence
Count distinct elements in every window
🔟 Advanced Techniques
These are critical for tougher questions often seen in top-tier interviews.
✅ Key Problems:
Maximum product subarray
Subarray with XOR K
Partition array into disjoint intervals
Strings
1. Sliding Window Pattern
Key Idea: Maintain a sliding window to check substrings or character frequencies.
Problems:
o Longest Substring Without Repeating Characters
o Minimum Window Substring
o Longest Substring with At Most K Distinct Characters
o Check if String Contains All Anagrams of Another String
2. Two Pointers Pattern
Key Idea: Use two pointers to manipulate string indices.
Problems:
Follow me on Instagram, You Tube, and LinkedIn for more tech-related content
.
o Valid Palindrome
o Reverse Words in a String
o Longest Palindromic Substring
o Compare Backspaced Strings
3. Prefix Sum / Cumulative Frequency
Key Idea: Use prefix sums or hashmaps for cumulative frequency calculations.
Problems:
o Substring with Equal 0s and 1️s (Binary Strings)
o Longest Substring with Balanced Parentheses
4. Hashing (Frequency Count)
Key Idea: Use hashmaps to store character frequencies or substrings.
Problems:
o Group Anagrams
o First Unique Character in a String
o Longest Substring with K Unique Characters
5. Dynamic Programming (DP)
Key Idea: Solve complex problems by breaking them into subproblems.
Problems:
o Longest Palindromic Subsequence
o Edit Distance
o Longest Common Subsequence
o Wildcard Matching
o Regular Expression Matching
6. Backtracking
Key Idea: Explore all possibilities by making choices and backtracking.
Follow me on Instagram, You Tube, and LinkedIn for more tech-related content
.
Problems:
o Generate All Permutations of a String
o Word Break Problem
o Palindrome Partitioning
7. String Searching Algorithms
Key Idea: Efficient algorithms to search substrings or patterns in strings.
Problems:
o Implement KMP Algorithm (Knuth-Morris-Pratt)
o Implement Rabin-Karp Algorithm
o Z-Algorithm for Pattern Searching
8. Trie (Prefix Tree)
Key Idea: Data structure for efficient prefix searching.
Problems:
o Longest Word in Dictionary
o Search Suggestions System
o Implement Autocomplete
9. Bit Manipulation for Strings
Key Idea: Use bitmasking for unique character operations.
Problems:
o Maximum Length of Concatenated String with Unique Characters
o Subsets with Unique Characters Using Bitmask
10. Regular Expressions
Key Idea: Use regex-like approaches to handle string pattern matching.
Problems:
o Regular Expression Matching (DP-based)
Follow me on Instagram, You Tube, and LinkedIn for more tech-related content
.
o Wildcard Matching
11. Mathematical String Problems
Key Idea: Strings that involve numerical computations or encodings.
Problems:
o Add Binary Strings
o Multiply Strings
o Decode Ways
12. Greedy Algorithms
Key Idea: Solve problems by making optimal choices at every step.
Problems:
o Rearrange Characters to Avoid Repetition
o Minimum Swaps to Make Strings Equal
13. Compression and Encoding
Key Idea: Work with compressing or encoding strings.
Problems:
o Run-Length Encoding
o Count and Say Problem
o Decode String
14. Miscellaneous Patterns
Rotations and Shifts:
o Check if Two Strings are Rotations of Each Other
o Minimum Shifts to Match Strings
String Multiplication and Power:
o Implement String to Integer Conversion (atoi)
o Power of Strings (Repeated Substrings)
Follow me on Instagram, You Tube, and LinkedIn for more tech-related content
.
2. Stack and Queue
Monotonic Stack/Queue
o Next Greater Element
o Largest Rectangle in Histogram
o Sliding Window Maximum
Stack Operations
o Valid Parentheses
o Evaluate Reverse Polish Notation
Queue Operations
o Implement LRU Cache
o Circular Queue
3. Linked List
Classic Problems
o Reverse a Linked List
o Detect and Remove Cycle in a Linked List
o Merge Two Sorted Lists
Advanced Patterns
o Flatten a Multilevel Doubly Linked List
o Add Two Numbers Represented as Linked Lists
4. Binary Search
Search Problems
o Search in Rotated Sorted Array
o Median of Two Sorted Arrays
Range Problems
o Kth Smallest/Largest Element in Sorted Matrix
Follow me on Instagram, You Tube, and LinkedIn for more tech-related content
.
o Allocate Minimum Pages
5. Graph
Graph Traversals
o BFS and DFS
o Connected Components
Shortest Path
o Dijkstra’s Algorithm
o Bellman-Ford Algorithm
Advanced Graph Problems
o Minimum Spanning Tree (Prim/Kruskal)
o Topological Sorting
6. Trees
Basic Tree Traversals
o Inorder, Preorder, Postorder
Tree Algorithms
o Lowest Common Ancestor
o Diameter of Binary Tree
o Zigzag Level Order Traversal
Binary Search Trees
o Validate BST
o Kth Smallest Element
7. Hashing
Frequency Count
o Two Sum
o Longest Substring with K Unique Characters
Subarray Problems
Follow me on Instagram, You Tube, and LinkedIn for more tech-related content
.
o Count Subarrays with Sum Divisible by K
8. Recursion and Backtracking
Classic Problems
o Subset Sum
o N-Queens Problem
String Backtracking
o Word Search
o Generate All Permutations of a String
9. Dynamic Programming
Knapsack Problems
o 0/1 Knapsack
o Subset Sum
String DP
o Longest Common Subsequence
o Edit Distance
Grid-Based DP
o Unique Paths
o Minimum Path Sum
10. Greedy Algorithms
Interval Problems
o Activity Selection Problem
o Minimum Platforms
Optimization Problems
o Huffman Encoding
o Fractional Knapsack
Follow me on Instagram, You Tube, and LinkedIn for more tech-related content
.
Advanced DSA Patterns
1. Tries
Prefix Matching
o Implement Trie
o Longest Word in Dictionary
Pattern Searching
o Word Search II
o Replace Words
2. Segment Trees and Fenwick Trees
Range Queries
o Range Sum Query
o Range Minimum Query
Lazy Propagation
o Range Updates in Segment Tree
3. Heap (Priority Queue)
K Problems
o Kth Largest Element in Array
o Merge K Sorted Lists
Advanced Problems
o Top K Frequent Elements
o Sliding Window Median
4. Bit Manipulation
Single Number Problems
o Find the Single Number (XOR Logic)
o Power of Two
Subsets Using Bitmasking
Follow me on Instagram, You Tube, and LinkedIn for more tech-related content
.
o Generate All Subsets
5. Mathematical Problems
Number Theory
o Sieve of Eratosthenes
o Modular Arithmetic
String and Numbers
o Multiply Strings
o Add Binary
Practice Approach
1. Solve 250+ curated problems covering these patterns.
2. Target platforms like LeetCode, Codeforces, and InterviewBit.
3. Focus on company-specific problems, especially from Google, Amazon, Flipkart,
etc.
4. Analyze problems to identify pattern overlaps (e.g., Sliding Window + Hashing).
Top DSA Creator on YouTube
1️. APNA College(6️.2️3️M) - (7️4️9) Apna College - YouTube (Baap k Baap)
2️. Abdul Bari(1️ M)
3️. Aditya Verma - Focuses on solving problems step-by-step, with special emphasis on
Dynamic Programming (DP).
4️. Love Babbar - Covers DSA problems with a practical approach and also has the famous
"4️5️0 DSA Questions" series.
5️. triver (Take U Forward) - Offers playlists on DSA, competitive programming, and system
design.
6️. CodeWithHarry - Beginner-friendly tutorials on DSA and coding.
7️. Pepcoding- Comprehensive coverage of DSA and coding problems.
8️. NeetcodeIO - (7️4️9) NeetCodeIO - YouTube
9. Neetcode (8️7️4️ K ) - My Brain after 5️6️9 Leetcode Problems
1️0. Gaurav Sen ( System Design and Algorithm)(6️07️ k ) - (7️4️9) Gaurav Sen - YouTube
1️1️. Anuj Bhaiya(5️07️k) - (7️4️9) Anuj Bhaiya - YouTube
1️2️. Neso Academy
Follow me on Instagram, You Tube, and LinkedIn for more tech-related content
.
Here’s The link:
Instagram: @codetocrackfaang
You Tube: Eng Shreya Singh
LinkedIn: Shreya Singh
Follow me on Instagram, You Tube, and LinkedIn for more tech-related content