Skip to main content
DSA Patterns

Why Learn by Patterns?

Most coding interviews test the same 22 core patterns repeatedly. Instead of solving 1000+ random problems, understanding these patterns helps you:
  • Recognize problem types instantly
  • Apply proven templates to new problems
  • Optimize solutions systematically
  • Explain your thought process clearly
The 80/20 Rule: 80% of interview problems can be solved using just 6 patterns: Two Pointers, Sliding Window, HashMap, Binary Search, DFS/BFS, and Dynamic Programming. Master these first!

Pattern Categories

Pattern Selection Flowchart

Use this decision tree when you encounter a new problem:

Quick Pattern Recognition Cheat Sheet

If you see…Think…
“sorted array”, “find pair with sum”Two Pointers
”contiguous subarray”, “window of size k”Sliding Window
”find in sorted”, “minimize/maximize”Binary Search
”frequency”, “anagram”, “contains”HashMap
”all paths”, “connected components”DFS
”shortest path”, “level order”BFS
”maximum/minimum with constraints”Dynamic Programming
”generate all”, “permutations”, “combinations”Backtracking
”optimal choice at each step”Greedy
”k largest/smallest”, “merge sorted”Heap
”matching brackets”, “undo”Stack
”prefix/autocomplete”Trie
”connected groups”, “union/merge”Union Find
STAMPS - For Two Pointer problems:
  • Sorted array?
  • Two elements needed?
  • Avoid nested loops?
  • Move based on comparison?
  • Pairs/Triplets?
  • Space O(1) possible?
SLIDE - For Sliding Window:
  • Subarray/Substring problem?
  • Length constraints?
  • Iterate once?
  • Dynamic window possible?
  • Expand and shrink?
DREAD - For Dynamic Programming:
  • Decision at each step?
  • Recurrence relation possible?
  • Every subproblem needed?
  • Answer from subproblems?
  • Duplicate subproblems?

Learning Path

1

Foundation (Week 1-2)

Start with Two Pointers, Sliding Window, and HashMap patterns. These appear in 40% of interview questions.Daily Goals: 2-3 easy problems + 1 medium problem
2

Core Patterns (Week 3-4)

Master Binary Search, DFS/BFS, and Stack/Queue patterns. Build intuition for when to apply each.Daily Goals: 1-2 easy + 2 medium problems
3

Intermediate (Week 5-6)

Tackle Dynamic Programming, Backtracking, and Greedy approaches. Focus on state definition.Daily Goals: 2-3 medium problems + analyze solutions
4

Advanced (Week 7-8)

Learn Trie, Union Find, Monotonic Stack, and Bit Manipulation for specialized problems.Daily Goals: 1-2 medium + 1 hard problem

8-Week Study Calendar

DayTopicProblems to Solve
1Two Pointers IntroTwo Sum II, Valid Palindrome
2Two Pointers Practice3Sum, Container With Most Water
3Sliding Window FixedMax Sum Subarray, Avg of Subarrays
4Sliding Window VariableLongest Substring Without Repeat
5HashMap BasicsTwo Sum, Contains Duplicate
6HashMap + FrequencyValid Anagram, Group Anagrams
7Review + Mixed PracticeSolve 3 random problems

Pattern Difficulty Matrix

PatternDifficultyFrequencyTime to LearnInterview Importance
Two PointersEasyVery High2-3 daysVery High
Sliding WindowEasyVery High2-3 daysVery High
HashMapEasyVery High1-2 daysVery High
Binary SearchMediumVery High3-4 daysVery High
DFS/BFSMediumHigh4-5 daysVery High
Stack/QueueEasyHigh2-3 daysHigh
HeapMediumMedium3-4 daysHigh
Dynamic ProgrammingHardVery High2-3 weeksVery High
BacktrackingMediumMedium4-5 daysHigh
GreedyMediumMedium3-4 daysMedium
TrieMediumLow2-3 daysMedium
Union FindMediumMedium3-4 daysHigh
Monotonic StackHardLow3-4 daysMedium
Bit ManipulationMediumLow2-3 daysLow

Company-Wise Pattern Frequency

  1. Dynamic Programming (25%)
  2. Graph Algorithms (20%)
  3. Binary Search (15%)
  4. Two Pointers/Sliding Window (15%)
  5. HashMap/HashSet (10%)
  6. Others (15%)

Success Tips

Spaced Repetition

Review solved problems after 1 day, 3 days, 7 days, and 14 days to build long-term memory.

Teach Others

Explain your solutions out loud or write blog posts. Teaching reinforces understanding.

Time Yourself

Practice with 45-minute limits. Real interviews are time-constrained.

Debug Without IDE

Practice tracing code on paper. Build mental debugging skills.
Common Mistakes to Avoid:
  • Jumping to code without understanding the problem
  • Not considering edge cases (empty input, single element, duplicates)
  • Ignoring time/space complexity until asked
  • Memorizing solutions instead of understanding patterns
Pro Tip: Focus on understanding the why behind each pattern, not just the how. This helps you adapt patterns to novel problems.