# Common Data Structures and Algorithms Patterns

## Pattern 1: Fast and Slow Pointers

| **Problem Link** | **Articles** | **Solution** |
| --- | --- | --- |
| [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/FastAndSlowPointers/LinkedListCycle/Solution.java) |
| [Happy Number](https://leetcode.com/problems/happy-number/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/FastAndSlowPointers/HappyNumber/Solution.java) |
| [Find the duplicate number](https://leetcode.com/problems/find-the-duplicate-number/description/) |  |  |

## Pattern 2: Sliding Window

| **Problem Link** | **Articles** | **Solution** |
| --- | --- | --- |
| [Maximum Average Subarray](https://leetcode.com/problems/maximum-average-subarray-i/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/SlidingWindow/MaximumAverageSubarray/Solution.java) |
| [Longest Substring Without Repeating Character](https://leetcode.com/problems/longest-substring-without-repeating-characters/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/SlidingWindow/LongestSubstringWithoutRepeatingCharacters/Solution.java) |
| [Minimum window substring](https://leetcode.com/problems/minimum-window-substring/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/SlidingWindow/MinimumWindowSubstring/Solution.java) |

## Pattern 3: Merge Intervals/Overlapping Intervals

| **Problem Link** | **Articles** | **Solution** |
| --- | --- | --- |
| [Merge Intervals](https://leetcode.com/problems/merge-intervals/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/MergedIntervals/MergeIntervals/Solution.java) |
| [Insert Intervals](https://leetcode.com/problems/insert-interval/description/) |  | [Linear Search](https://github.com/subhakundu/DsAlgoPractice/blob/main/MergedIntervals/InsertIntervals/LinearSearch/Solution.java), [Binary Search](https://github.com/subhakundu/DsAlgoPractice/blob/main/MergedIntervals/InsertIntervals/BinarySearch/Solution.java) |
| [Non-overlapping Intervals](https://leetcode.com/problems/non-overlapping-intervals/description/) |  |  |

## Pattern 4: **LinkedList In-place Reversal**

| **Problem Link** | **Articles** | **Solution** |
| --- | --- | --- |
| [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/description/) |  | [Iterative](https://github.com/subhakundu/DsAlgoPractice/blob/main/LinkedListInPlaceReversal/Iterative/Solution.java), [Recursive](https://github.com/subhakundu/DsAlgoPractice/blob/main/LinkedListInPlaceReversal/Recursive/Solution.java) |
| [Reverse Linked List II](https://leetcode.com/problems/reverse-linked-list-ii/description/) |  |  |
| [Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs/description/) |  |  |

## Pattern 5: Prefix Sum

| **Problem Link** | **Articles** | **Solution** |
| --- | --- | --- |
| [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/PrefixSum/RangeSumQuery.java) |
| [Contiguous Array](https://leetcode.com/problems/contiguous-array/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/PrefixSum/ContiguousArray.java) |
| [Subarray Sum Equals K](https://leetcode.com/problems/subarray-sum-equals-k/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/tree/main/PrefixSum/SubarraySumEqualsK) |

## Pattern 6: **Top ‘K’ Elements**

| **Problem Link** | **Articles** | **Solution** |
| --- | --- | --- |
| [Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/Heap/KthLargetElementInAnArray.java) |
| [Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/Heap/TopKFrequentElements.java) |
| [Find K Pairs with Smallest Sums](https://leetcode.com/problems/find-k-pairs-with-smallest-sums/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/Heap/FindKPairsWithSmallestSum.java) |

## Pattern 7: Binary Search

| **Problem Link** | **Articles** | **Solution** |
| --- | --- | --- |
| [Search in a rotated sorted array](https://leetcode.com/problems/search-in-rotated-sorted-array/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/tree/main/BinarySearch/FindingElementInRotatedArray) |
| [Find Minimum in a rotated sorted array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/BinarySearch/FindMinimumInRotatedSortedArray.java) |
| [Search a 2D matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/tree/main/BinarySearch/SearchInA2DMatrix) |

## Pattern 8: Binary Tree Traversal

| **Problem Link** | **Articles** | **Solution** |
| --- | --- | --- |
| [Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/BinaryTreeTraversal/BinaryTreePaths.java) |
| [K-th Smallest Element in BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst/description/) |  | [Recursive](https://github.com/subhakundu/DsAlgoPractice/blob/main/BinaryTreeTraversal/KthSmallestElement/Recursive/Solution.java), [Iterative](https://github.com/subhakundu/DsAlgoPractice/blob/main/BinaryTreeTraversal/KthSmallestElement/Iterative/Solution.java) |
| [Binary Tree Maximum Path Sum](https://leetcode.com/problems/binary-tree-maximum-path-sum/description/) |  |  |
| [Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/tree/main/Tree/InorderTraversal) |
| [Symmetric Tree](https://leetcode.com/problems/symmetric-tree/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/Tree/SymmetricTree/Solution.java) |

## Pattern 9: Depth First Search

| **Problem Link** | **Articles** | **Solution** |
| --- | --- | --- |
| [Clone Graph](https://leetcode.com/problems/clone-graph/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/Graph/ClonedGraph/DFS.java) |
| [Path Sum II](https://leetcode.com/problems/path-sum-ii/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/Tree/PathSum2/Solution.java) |
| [Course Schedule II](https://leetcode.com/problems/course-schedule-ii/description/) |  |  |
| [Same Tree](https://leetcode.com/problems/same-tree/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/DepthFirstSearch/SameTree/Solution.java) |
| [Number of Provinces](https://leetcode.com/problems/number-of-provinces/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/Graph/NumberOfProvinces/Solution.java) (DFS) |

## Pattern 10: Breadth First Search

| **Problem Link** | **Articles** | **Solution** |
| --- | --- | --- |
| [Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/description/) |  | [GitHub](https://github.com/subhakundu/DsAlgoPractice/blob/main/BreadthFirstSearch/BinaryTreeLevelOrderTraversal.java) |
| [Rotting Oranges](https://leetcode.com/problems/rotting-oranges/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/Graph/RottenOranges/Solution.java) |
| [Word Ladder](https://leetcode.com/problems/word-ladder/description/) |  |  |
| [Clone Graph](https://leetcode.com/problems/clone-graph/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/Graph/ClonedGraph/BFS.java) |
| [If Path Exists](https://leetcode.com/problems/find-if-path-exists-in-graph/description/) |  | [BFS](https://github.com/subhakundu/DsAlgoPractice/blob/main/Graph/PathFinding/IfPathExists/BFS/Solution.java), [Union Find](https://github.com/subhakundu/DsAlgoPractice/blob/main/Graph/PathFinding/IfPathExists/UnionFind/Solution.java) |

## Pattern 11: **Matrix Traversal**

| **Problem Link** | **Articles** | **Solution** |
| --- | --- | --- |
| [Flood Fill](https://leetcode.com/problems/flood-fill/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/Graph/Matrix/FloodFill/Solution.java) |
| [Number of Islands](https://leetcode.com/problems/number-of-islands/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/Graph/Matrix/NumberOfIslands/Solution.java) |
| [Surrounded Regions](https://leetcode.com/problems/surrounded-regions/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/Graph/Matrix/SurroundedRegions/Solution.java) |
| [Number of Closed Islands](https://leetcode.com/problems/number-of-closed-islands/description/) |  | [Without global variable](https://github.com/subhakundu/DsAlgoPractice/tree/main/Graph/Matrix/NumberOfClosedIslands/WithoutGlobalVariable), [with global variable](https://github.com/subhakundu/DsAlgoPractice/tree/main/Graph/Matrix/NumberOfClosedIslands/WithGlobalVariable) (cleaner, but not best practice) |

## Pattern 12: Backtracking

| **Problem Link** | **Articles** | **Solution** |
| --- | --- | --- |
| [Permutations](https://leetcode.com/problems/permutations/description/) | [Notes](https://blog.thecuriouscoder.in/backtracking-generating-permutations) | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/Backtracking/Permutations.java) |
| [Subsets](https://leetcode.com/problems/subsets/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/Backtracking/Subsets.java) |
| [N-queens](https://leetcode.com/problems/n-queens/description/) |  |  |

## Pattern 13: Monotonic Stack

| **Problem Link** | **Articles** | **Solution** |
| --- | --- | --- |
| [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i/description/) |  | [Github](https://github.com/subhakundu/DsAlgoPractice/blob/main/MonotonicStack/NextGreaterElementI/Solution.java) |
| [Daily Temperatures](https://leetcode.com/problems/daily-temperatures/description/) |  |  |
| [Largest Rectangle in Histogram](https://leetcode.com/problems/largest-rectangle-in-histogram/description/) |  |  |

## Pattern 14: Generic Graphs

| **Problem Link** | **Articles** | **Solution** |
| --- | --- | --- |
| [Minimum Number of Vertices to Reach All Nodes](https://leetcode.com/problems/minimum-number-of-vertices-to-reach-all-nodes/description/) |  | [Solution](https://github.com/subhakundu/DsAlgoPractice/blob/main/Graph/MinimumNumberOfVertices/Solution.java) |
|  |  |  |
