Problem Solving Patterns: Basic To Advanced
1. Sliding Window
Description: Used for contiguous subarray problems by maintaining a window that expands or shrinks.
LeetCode Problems:
3. Longest Substring Without Repeating Characters
424. Longest Repeating Character Replacement
209. Minimum Size Subarray Sum
2. Two Pointers
Description: Uses two pointers to traverse a data structure efficiently.
LeetCode Problems:
167. Two Sum II — Input Array Is Sorted
125. Valid Palindrome
15. 3Sum
3. Fast & Slow Pointers (Floyd’s Cycle Detection)
Description: Uses two pointers moving at different speeds to detect cycles.
LeetCode Problems:
141. Linked List Cycle
142. Linked List Cycle II
202. Happy Number
4. Frequency Counter
Description: It uses a hash map to count the occurrences of elements.
LeetCode Problems:
242. Valid Anagram
387. First Unique Character in a String
49. Group Anagrams
5. Binary Search
Description: Efficiently finds an element in a sorted array by repeatedly dividing the search space.
LeetCode Problems:
704. Binary Search
33. Search in Rotated Sorted Array
153. Find Minimum in Rotated Sorted Array
6. Divide and Conquer
Description: Breaks problems into smaller subproblems, solves them recursively, and combines results.
LeetCode Problems:
53. Maximum Subarray (Kadane’s Algorithm can also be used)
169. Majority Element
241. Different Ways to Add Parentheses
7. Dynamic Programming (DP)
Description: Solves overlapping subproblems using memoization or tabulation.
LeetCode Problems:
70. Climbing Stairs
300. Longest Increasing Subsequence
416. Partition Equal Subset Sum
8. Backtracking
Description: Explores all possible solutions recursively and backtracks when a condition is not met.
LeetCode Problems:
78. Subsets
39. Combination Sum
51. N-Queens
9. Greedy Algorithm
Description: Makes local optimal choices at each step to get a globally optimal solution.
LeetCode Problems:
55. Jump Game
435. Non-overlapping Intervals
621. Task Scheduler
10. Graph Traversal (BFS & DFS)
Description: Uses BFS for shortest path problems and DFS for depth-first exploration.
LeetCode Problems:
200. Number of Islands
133. Clone Graph
127. Word Ladder (BFS)
11. Union-Find (Disjoint Set Union — DSU)
Description: Helps detect cycles and find connected components.
LeetCode Problems:
Get Mahfuzur Rahman’s stories in your inbox
Join Medium for free to get updates from this writer.
684. Redundant Connection
547. Number of Provinces
990. Satisfiability of Equality Equations
12. Topological Sorting
Description: Orders tasks in a dependency graph using DFS or Kahn’s algorithm.
LeetCode Problems:
207. Course Schedule
210. Course Schedule II
329. Longest Increasing Path in a Matrix
13. Bit Manipulation
Description: Uses bitwise operations for optimization and mathematical tricks.
LeetCode Problems:
136. Single Number
78. Subsets (Bitmasking approach)
137. Single Number II
14. Prefix Sum / Cumulative Sum
Description: Precomputes sums for fast range sum queries.
LeetCode Problems:
303. Range Sum Query — Immutable
523. Continuous Subarray Sum
560. Subarray Sum Equals K
15. Monotonic Stack / Queue
Description: Uses a stack or queue to maintain increasing/decreasing sequences.
LeetCode Problems:
739. Daily Temperatures
84. Largest Rectangle in Histogram
496. Next Greater Element I
16. Meet in the Middle
Description: Splits a problem into two halves to reduce complexity.
LeetCode Problems:
1755. Closest Subsequence Sum
1498. Number of Subsequences That Satisfy the Given Sum Condition
17. Kadane’s Algorithm
Description: Finds the maximum sum subarray in O(n) time.
LeetCode Problems:
53. Maximum Subarray
918. Maximum Sum Circular Subarray
18. Tree Traversals (DFS & BFS)
Description: DFS uses Preorder, Inorder, Postorder; BFS explores level by level.
LeetCode Problems:
102. Binary Tree Level Order Traversal (BFS)
94. Binary Tree Inorder Traversal (DFS)
124. Binary Tree Maximum Path Sum
19. Heaps (Priority Queue)
Description: Uses a min-heap or max-heap to efficiently find top elements.
LeetCode Problems:
703. Kth Largest Element in a Stream
215. Kth Largest Element in an Array
295. Find Median from Data Stream
20. Top-K Elements Pattern
Description: Finds the top k largest or smallest elements using a heap or quickselect.
LeetCode Problems:
347. Top K Frequent Elements
973. K Closest Points to Origin
692. Top K Frequent Words
21. Sliding Window Maximum (Deque Approach)
Description: Uses a deque to maintain max/min values efficiently.
LeetCode Problems:
239. Sliding Window Maximum
1696. Jump Game VI
22. Morris Traversal (Tree Traversal Without Extra Space)
Description: Inorder traversal of a binary tree in O(1) extra space.
LeetCode Problems:
94. Binary Tree Inorder Traversal (without recursion or stack)
NB: ChatGPT helped me generate this List.






![Python DSA Coding Interview Series:15/29 [Tree BFS, Binary Search Trees and Paths]](https://miro.medium.com/v2/resize:fit:1358/format:webp/1*WiqEcxsecBYN5dkcpD44ZA.png)
