A collection of reusable code snippets that can be used for code interview problems
✅ = Fully Implemented 🔄 = In Progress ⏳ = Planned
- ✅ Prefix Sum
- ✅ Two Pointers
- ✅ Sliding Window
- ✅ Fast & Slow Pointers
- ✅ LinkedList Reversal
- ✅ Monotonic Stack
- ✅ Top K Elements
- ✅ Overlapping Intervals
- ✅ Modified Binary Search
- ✅ Tree Traversal
- ✅ DFS
- ✅ BFS
- ✅ Matrix Traversal
- ✅ Backtracking
- ✅ Basic Dynamic Programming
- ✅ Fibonacci Sequence
- ✅ Kadane's Algorithm
- ✅ 0/1 Knapsack
- ✅ Unbounded Knapsack
- ✅ LCS
- ✅ LIS
- ✅ Palindromic Subsequence
- ✅ Edit Distance
- ✅ Subset Sum
- ✅ String Partition
- ✅ Catalan Numbers
- ✅ Matrix Chain Multiplication
- ✅ Count Distinct Ways
- ✅ Grid DP
- ✅ Tree DP
- ✅ Graph DP
- ✅ Digit DP
- ✅ Bitmasking DP
- ✅ Probability DP
- ✅ State Machine DP
- 15 LeetCode Patterns by Ashish Pratap Singh
- 20 Patterns to Master Dynamic Programming by Ashish Pratap Singh
- LeetCode
- HackerRank
- CodeForces
-
"LeetCode was HARD until I Learned these 15 Patterns" by Ashish Pratap Singh
- Comprehensive coverage of core algorithmic patterns
- Practical examples and problem classifications
- Pattern-based problem-solving approach
-
"20 Patterns to Master Dynamic Programming" by Ashish Pratap Singh
- In-depth coverage of DP patterns
- Pattern categorization from basic to advanced
- Problem-pattern mapping for DP
- "Introduction to Algorithms" (CLRS)
- "Algorithms" by Robert Sedgewick
- "Dynamic Programming for Coding Interviews"
- AlgoMaster YouTube Channel
- Back To Back SWE
- Tech Interview Pro
We welcome contributions! Please see our CONTRIBUTING.md for details on:
- Adding new patterns
- Improving implementations
- Adding problem solutions
- Enhancing documentation
-
Identify Key Characteristics:
- Sorted array? → Two Pointers
- Substring/Subarray? → Sliding Window
- Optimal substructure? → Dynamic Programming
-
Consider Constraints:
- Time complexity requirements
- Space complexity limits
- Input size ranges
-
Common Pattern Indicators:
def select_pattern(characteristics: Dict[str, bool]) -> str: if characteristics.get('sorted_array'): return 'Two Pointers' elif characteristics.get('subarray_sum'): return 'Prefix Sum' elif characteristics.get('optimization'): return 'Dynamic Programming' # ... more conditions
-
Time Complexity:
- Always consider the most efficient solution
- Document complexity in comments
- Explain trade-offs
-
Space Optimization:
- Consider in-place algorithms when possible
- Use space-time trade-offs wisely
- Document space complexity
-
Code Style:
- Follow Google Python Style Guide
- Use meaningful variable names
- Add comprehensive docstrings
Contributions are welcome! Please:
- Follow the code style guide
- Add comprehensive tests
- Document complexity analysis
- Include example problems
- Update implementation status
MIT License - see LICENSE file for details.
Happy Coding! 🚀
A comprehensive collection of coding interview patterns combining algorithmic techniques and dynamic programming approaches.
-
- Purpose
- How to Use This Guide
- Repository Structure
-
- Array & String Patterns
- Prefix Sum
- Two Pointers
- Sliding Window
- Linked List Patterns
- Fast & Slow Pointers
- In-place Reversal
- Stack & Queue Patterns
- Monotonic Stack
- Priority Queue (Top K)
- Binary Search Patterns
- Modified Binary Search
- Search Space Reduction
- Tree & Graph Patterns
- Tree Traversals (PreOrder, InOrder, PostOrder)
- BFS/DFS
- Matrix Traversal
- Advanced Patterns
- Backtracking
- Intervals
- Cyclic Sort
- Array & String Patterns
-
- Basic Patterns
- Fibonacci Style
- Kadane's Algorithm
- Knapsack Patterns
- 0/1 Knapsack
- Unbounded Knapsack
- String Patterns
- LCS (Longest Common Subsequence)
- LIS (Longest Increasing Subsequence)
- Palindromic Subsequences
- Edit Distance
- Grid & Graph Patterns
- Grid Traversal
- Tree DP
- Graph DP
- Advanced DP Patterns
- State Machine
- Probability DP
- Digit DP
- Bitmask DP
- Basic Patterns
-
- How to Identify Patterns
- Common Problem Types
- Pattern Selection Flowchart
-
- Code Style
- Best Practices
- Complexity Analysis
- Testing Strategies
-
- LeetCode Problems by Pattern
- Common Variations
- Solution Templates
-
- Learning Path
- Practice Strategy
- Interview Preparation Tips