Skip to content

joxoleon/dsa-patterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DSA Pattern Library (Interview-Optimized)

This document lists the core algorithmic patterns that cover 90–95% of FAANG-level coding interview problems.
Mastering these patterns to procedural fluency enables solving medium problems in 2–5 minutes.


1. Linked List Patterns (5 Core Templates)

Core

  1. Reverse Linked List (iterative)
  2. Merge Two Lists (dummy head pattern)
  3. Partition Into Two Lists (small/big dummy heads)
  4. Fast/Slow Pointers
    • middle of list
    • cycle detection (Floyd)
    • reorder list
  5. Remove/Skip Nodes With Dummy
    • remove Nth from end
    • skip duplicates
    • delete specific node pattern

2. Two-Pointer & Sliding Window Patterns

Core

  1. Two-Pointer Convergence (sorted arrays)
  2. Opposing Pointers for Optimization (max/min problems)
  3. Sliding Window – Fixed Size
  4. Sliding Window – Variable Size
  5. Sliding Window – Longest Substring With Constraints
  6. Sliding Window – Shortest Substring With Constraints

Core (Prefix/Hash)

  1. Prefix Sums + Hashmap
  2. Subarray Sum = K Pattern

Secondary

  1. Dutch National Flag (3-Way Partition)

3. Stack Patterns

Core

  1. Monotonic Increasing Stack
    • next greater element
    • stock span
  2. Monotonic Decreasing Stack
    • largest rectangle in histogram
    • max rectangle in matrix
  3. Parentheses Stack Patterns
    • valid parentheses
    • minimum removals
    • longest valid parentheses

4. Queue / Deque Patterns

Core

  1. Sliding Window Max/Min Using Deque
  2. BFS Level-Order Traversal
  3. BFS Shortest Path in Grid Graph

5. Binary Search Patterns

Core

  1. Standard Binary Search Template
  2. Binary Search on Answer (parametric search)
  3. Lower-Bound / Upper-Bound
  4. Search in Rotated Sorted Array

6. Tree Patterns

Core

  1. DFS Recursion Patterns
    • preorder
    • inorder
    • postorder
  2. BFS Tree Traversal
  3. Lowest Common Ancestor
    • binary tree
    • binary search tree
  4. Diameter / Depth Patterns
    • max depth
    • diameter of binary tree
  5. Binary Tree Serialization / Deserialization (BFS-based)

Secondary

  1. BST Insert / Delete / Search (conceptual + implementation)

7. Graph Patterns

Core

  1. DFS Graph Template
  2. BFS Graph Template
  3. Topological Sort (Kahn’s Algorithm)
  4. Cycle Detection in Directed Graph
    • DFS recursion stack
    • Kahn’s indegree method
  5. Connected Components (BFS or DFS)
  6. Union-Find (Disjoint Set Union)
    • path compression
    • union by rank
  7. Dijkstra’s Algorithm (Min-Heap Pattern)

8. Dynamic Programming Patterns

Core

  1. Fibonacci / Linear DP Template
  2. Knapsack DP
    • classic 2D
    • optimized 1D rolling array
  3. Subsequence DP
    • LCS
    • edit distance
    • LIS
  4. Palindrome DP
    • palindromic substrings
    • longest palindromic substring
  5. Partition DP
    • subset sum
    • equal partition
  6. Interval DP
    • burst balloons
    • matrix chain multiplication

Secondary

  1. Bitmask DP (rare, niche)

9. Intervals / Greedy Patterns

Core

  1. Sort + Merge Intervals
  2. Insert Interval
  3. Select Maximum Non-Overlapping Intervals (classic greedy)
  4. Gas Station / Circular Tour
  5. Meeting Rooms Scheduling (heap-based)

10. Heap & Misc Patterns

Core

  1. Kth Largest Element
    • min-heap of size k
    • quickselect
  2. Top-K Frequency (heap or bucket sort)
  3. Heap-Select Patterns
  4. Prefix Product / Postfix Product (product of array except self)

Optional

  1. Sweep Line
  2. Reservoir Sampling
  3. Randomized Quickselect

Summary

Core patterns to master: 51
These are sufficient to solve nearly all FAANG-level technical interview questions with speed and confidence.


Recommended Usage

  • Treat these as templates, not problems.
  • Drill 3 patterns per day for 10–15 minutes.
  • Aim for procedural fluency: solutions should be reflexive, fast, automatic.
  • Build a repo with one directory per pattern containing:
    • Python template
    • Example problems
    • Practice implementations
    • Notes + pitfalls

Master these → Mediums become trivial, hards become mechanical.

Repository Index

  • patterns/01-linked-list-reverse/: core iterative reverse template with notes.
  • patterns/01_linked_list_patterns.py: full linked list pattern implementations (reverse, merge, partition, fast/slow, remove with dummy).
  • patterns/02_two_pointers_and_windows.py: two-pointer + sliding window patterns (fixed, variable, prefix-sum/hash) ready to use.
  • shared/: reusable structures such as ListNode plus build/print helpers.

About

DSA Pattern Library (Interview-Optimized)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages