Skip to content

Latest commit

 

History

History
168 lines (122 loc) · 2.56 KB

File metadata and controls

168 lines (122 loc) · 2.56 KB

DSA Patterns Organized by Data Structure

Learn the data structure first, then the patterns commonly used on it.


1. Arrays

Hashing

  • Two Sum
  • Contains Duplicate

Two Pointers

  • 3Sum
  • 3Sum Closest
  • 4Sum

Sliding Window

  • Longest Substring Without Repeating Characters
  • Longest Repeating Character Replacement
  • Minimum Window Substring

Prefix Sum / Kadane's Algorithm

  • Maximum Subarray
  • Product of Array Except Self
  • Count of Range Sum

Binary Search

  • Find Minimum in Rotated Sorted Array
  • Search in Rotated Sorted Array

Greedy

  • Best Time to Buy and Sell Stock

2. Strings

Hashing

  • Valid Anagram
  • Group Anagrams

Two Pointers

  • Valid Palindrome

Sliding Window

  • Longest Substring Without Repeating Characters
  • Longest Repeating Character Replacement
  • Minimum Window Substring

3. Matrix (2D Arrays)

Matrix Traversal

  • Set Matrix Zeroes
  • Spiral Matrix
  • Rotate Image

DFS / Backtracking

  • Word Search

Dynamic Programming

  • Unique Paths
  • Unique Paths II
  • Minimum Path Sum
  • Pascal's Triangle
  • Dungeon Game
  • Maximal Square

Monotonic Stack

  • Maximal Rectangle

4. Stack

Monotonic Stack

  • Largest Rectangle in Histogram
  • Maximal Rectangle
  • Next Greater Element

Concepts

  • Previous Greater Element
  • Previous Smaller Element
  • Next Greater Element
  • Next Smaller Element

5. Tree / Graph

DFS

  • Path Finding
  • Maze Problems

BFS

  • Shortest Path Problems
  • Level Order Traversal

Backtracking

  • Word Search
  • Path Enumeration

6. Divide & Conquer

Merge Sort Based

  • Count of Smaller Numbers After Self
  • Count of Range Sum

Pattern Summary

Data Structure Important Patterns
Array Hashing, Two Pointers, Sliding Window, Prefix Sum, Binary Search, Greedy
String Hashing, Two Pointers, Sliding Window
Matrix Traversal, DFS, Backtracking, Dynamic Programming
Stack Monotonic Stack
Tree DFS, BFS
Graph DFS, BFS
Advanced Arrays Divide & Conquer

Interview Preparation Order

Arrays

  1. Hashing
  2. Two Pointers
  3. Sliding Window
  4. Prefix Sum
  5. Binary Search
  6. Greedy

Strings

  1. Hashing
  2. Two Pointers
  3. Sliding Window

Matrix

  1. Matrix Traversal
  2. DFS / Backtracking
  3. Dynamic Programming

Advanced

  1. Monotonic Stack
  2. Divide & Conquer

80/20 Rule

Master these patterns:

  • Hashing
  • Two Pointers
  • Sliding Window
  • Prefix Sum
  • Binary Search
  • DFS/BFS
  • Dynamic Programming
  • Monotonic Stack

These alone solve roughly 80–90% of coding interview problems.