- Repository Overview
- Intended Usage
- File Naming Convention
- Example Usage
- Python Solution Structure
- LeetCode Commandments
- Problem-Solving Procedure
- Resources
- Recommended Problems
- Other Tips
This template repository is created to be used to organize LeetCode and data-structures/algorithms practice, organized into numbered pattern folders that follow a recommended study progression. Each top-level directory represents a core problem pattern such as Hash, Two Pointers, Sliding Window, BFS, DP, and more.
Inside each pattern directory:
- learning/ — where all new problems begin
- practice/ — spaced-repetition review folders (One Day, One Week, One Month)
- easy/, medium/, hard/ — mastered problems organized by difficulty
The numbering of folders (e.g., 2 Hash, 3 Two Pointers, 4 Sliding Window, etc.) indicates a suggested priority order for learning each pattern.
Start every new problem in the learning/ folder. As your understanding improves, move the problem into one of the practice folders—One Day, One Week, or One Month—depending on your confidence level. Review the problems according to their folder interval. Once you consistently solve a problem without assistance, move it into the appropriate easy, medium, or hard folder under its pattern to mark it as mastered.
<number>-<simplified-title>.py
<number>-<simplified-title>.md
Examples:
258-add-digits.py
001-two-sum.md
# Create problem files at repo root
pwsh .\new.ps1 -name "258-add-digits"
# Create problem files inside a specific pattern folder
pwsh .\new.ps1 -name "001-two-sum" -folder "hash"
Each problem’s Python file should contain all solution variants in one file, using separate classes to keep approaches cleanly divided.
Example:
# Iterative digit-summing approach
# Time: O(log n)
# Space: O(log n)
class Solution:
def addDigits(self, num: int) -> int:
while num >= 10:
total = 0
for d in str(num):
total += int(d)
num = total
return num
# Digital root formula (number theory)
# Time: O(1)
# Space: O(1)
class OptimalSolution:
def addDigits(self, num: int) -> int:
if num == 0:
return 0
return 1 + (num - 1) % 9- Limit time on a stuck problem — Don’t spend more than 15–20 minutes completely stuck; after a real attempt, switch to learning the concept.
- Analyze constraints first — Input size and limits indicate the intended algorithm and whether brute force is viable.
- Use examples as a guide — Expand the given examples and create additional ones to uncover hidden patterns.
- Solve the simpler version first — Reduce the problem to its core; scale up only after the logic is clear.
- Optimize in phases — Start with correctness, then improve performance; don’t force an optimal solution immediately.
- Explain your thinking — Clear reasoning exposes gaps and aligns with interview expectations.
- Recognize patterns — Label each solved problem by pattern (hashing, two pointers, DP, BFS, etc.) to strengthen intuition.
- Review after solving — Study official or community solutions and extract at least one new insight.
- Re-solve deliberately — Revisit problems after 1 day, 1 week, and 1 month to reinforce long-term retention.
- Prioritize mastery over volume — Deep understanding of fewer problems leads to stronger overall performance.
Summarize the task in one or two sentences. Clarify what must be computed and under what conditions.
- Determine input types, ranges, and constraints
- Determine the output type and exact expected behavior
- Note edge conditions such as empty input, duplicates, or negative values
- Simulate each provided example step by step
- Create at least one additional example
- Confirm you understand how the correct output is produced
- Look for repeated behavior in examples
- Identify key relationships
- Map the problem to known patterns when possible
- Decide the high-level strategy
- Write clear pseudocode
- Ensure the pseudocode aligns with observed rules
- Implement step by step in Python
- Keep implementation simple
- Use descriptive variable names
- Test all provided examples
- Add edge cases
- Verify correctness before optimizing
- Compare different viable approaches
- Note trade-offs and when each alternative is preferred
- Identify time complexity
- Identify space complexity
- Ensure the solution meets problem constraints
- Summarize the pattern used
- Note any confusions and how they were resolved
- Consider adding the concept to spaced-repetition practice
- LeetCode Patterns - Seanprashad
- LeetCode Patterns Repository - Seanprashad
- Beginner's Guide - LeetCode
- Top Interview Questions - LeetCode
- NeetCode 150
Easy – Learning
- 1. Two Sum — core intro to hash maps for constant-time lookups
- 242. Valid Anagram — simple frequency counting pattern
- 349. Intersection of Two Arrays — foundational use of hash sets
Medium – Practice
- 49. Group Anagrams — canonical grouping-by-signature hashmap problem
- 560. Subarray Sum Equals K — teaches prefix sum + hashmap combo
Hard – Mastery
- 146. LRU Cache — classic design problem using hashmap + linked list
Easy – Learning
- 125. Valid Palindrome — clean beginner two-pointer pattern
- 344. Reverse String — left/right pointer fundamentals
- 88. Merge Sorted Array — backward merging with dual pointers
Medium – Practice
- 15. 3Sum — standard sorted-array two-pointer interview problem
- 19. Remove Nth Node From End of List — moving window pointers on linked list
Hard – Mastery
- 42. Trapping Rain Water — optimized two-pointer solution to a common hard problem
Easy – Learning
- 121. Best Time to Buy and Sell Stock — introduces shrinking/expanding window ideas
- 643. Maximum Average Subarray I — fixed-window basics
- 3. Longest Substring Without Repeating Characters — best beginner variable-window problem
Medium – Practice
- 209. Minimum Size Subarray Sum — shrinking window optimization
- 567. Permutation in String — sliding window with character counts
Hard – Mastery
- 76. Minimum Window Substring — most important hard window problem
Easy – Learning
- 704. Binary Search — essential template
- 35. Search Insert Position — boundary logic practice
- 69. Sqrt(x) — binary search on answer space
Medium – Practice
- 33. Search in Rotated Sorted Array — heavily repeated interview problem
- 34. Find First and Last Position of Element — teaches binary search for boundaries
Hard – Mastery
- 4. Median of Two Sorted Arrays — gold-standard advanced binary search problem
Easy – Learning
- 455. Assign Cookies — introduces greedy choice property
- 860. Lemonade Change — straightforward greedy bookkeeping
- 53. Maximum Subarray — Kadane’s algorithm, essential for interviews
Medium – Practice
- 55. Jump Game — common real interview greedy
- 134. Gas Station — teaches global vs local greedy reasoning
Hard – Mastery
- 135. Candy — non-trivial two-pass greedy construction
Easy – Learning
- 75. Sort Colors — Dutch National Flag, common interview pattern
- 88. Merge Sorted Array — reinforces sorting fundamentals
- 1122. Relative Sort Array — frequency-based sorting approach
Medium – Practice
- 347. Top K Frequent Elements — sorting/heap hybrid; heavily used
- 451. Sort Characters by Frequency — key frequency bucket-sort idea
Hard – Mastery
- 179. Largest Number — comparator logic and custom sorting
Easy – Learning
- 1046. Last Stone Weight — simplest intro to priority queue
- 703. Kth Largest Element in a Stream — fixed-size heap pattern
- 1167. Minimum Cost to Connect Sticks — Huffman-style greedy with heap
Medium – Practice
- 215. Kth Largest Element in an Array — top 5 most common heap problem
- 973. K Closest Points to Origin — common geometric heap question
Hard – Mastery
- 23. Merge k Sorted Lists — multi-list merging using min-heap
Easy – Learning
- 20. Valid Parentheses — core stack introduction
- 496. Next Greater Element I — intro to monotonic decreasing stack
- 739. Daily Temperatures — most common interview monotonic stack example
Medium – Practice
- 503. Next Greater Element II — circular array monotonic stack
- 402. Remove K Digits — greedy + monotonic stack for smallest sequence
Hard – Mastery
- 84. Largest Rectangle in Histogram — definitive monotonic stack hard problem
Easy – Learning
- 102. Binary Tree Level Order Traversal — pure BFS template
- 104. Maximum Depth of Binary Tree — simple BFS traversal
- 200. Number of Islands — top interview grid traversal problem
Medium – Practice
- 994. Rotting Oranges — multi-source BFS
- 127. Word Ladder — classic shortest path in implicit graph
Hard – Mastery
- 1293. Shortest Path in a Grid with Obstacles Elimination — BFS with state and constraints
Easy – Learning
- 112. Path Sum — clean recursive DFS
- 226. Invert Binary Tree — DFS transformation pattern
- 101. Symmetric Tree — recursive mirrored DFS
Medium – Practice
- 200. Number of Islands — essential DFS grid traversal
- 133. Clone Graph — DFS with visited map
Hard – Mastery
- 212. Word Search II — DFS + trie with pruning
Easy – Learning
- 70. Climbing Stairs — intro recurrence
- 198. House Robber — optimal substructure reasoning
- 746. Min Cost Climbing Stairs — simple DP recurrence variation
Medium – Practice
- 300. Longest Increasing Subsequence — widely asked DP
- 322. Coin Change — classic knapsack-style DP
Hard – Mastery
- 72. Edit Distance — foundational advanced DP
Easy – Learning
- 78. Subsets — core combinatorial DFS
- 46. Permutations — fundamental backtracking template
- 39. Combination Sum — teaches branching and pruning
Medium – Practice
- 17. Letter Combinations of a Phone Number — mapping + DFS
- 90. Subsets II — handling duplicates cleanly
Hard – Mastery
- 51. N-Queens — iconic backtracking mastery problem
- Use binary search for efficient lookups
- Use two pointers for pair-sum, window, or convergence patterns
- Use backtracking to generate all combinations, subsets, or permutations
- Use DFS for depth-focused traversal or recursive structural checks
- Use BFS for level-order traversal or shortest-path–style logic
- Use DFS to explore connected components or detect cycles
- Use BFS for shortest path in unweighted graphs or layer-based exploration
- Use two pointers for fast/slow traversal, cycle detection, or middle-finding
- Use a stack to simulate recursive behavior manually
- Swap values between indices to avoid extra storage
- Reuse existing slots or encode multiple values in one place when possible
- Use dynamic programming for optimal substructure problems
- Use a sliding window when the subarray is contiguous with monotonic constraints
- Use a heap for efficient K-selection
- Use QuickSelect for average-linear Kth-element selection
- Use a hash map to count or compare frequencies
- Use a trie for prefix-based queries or dictionary-style lookup
- Use a map/set for O(1) access with O(n) space
- Sort the input when ordering simplifies logic to O(n log n) time and O(1) extra space