Skip to content

Structured LeetCode practice template with numbered pattern folders, spaced-repetition review (Learning → One Day → One Week → One Month), and auto-generated .md/.py problem files. Designed for organized study, long-term mastery, and clean, repeatable workflows.

License

Notifications You must be signed in to change notification settings

silveralcid/leetcode-template

Repository files navigation

LeetCode

Table of Contents

Repository Overview

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.

Intended Usage

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.

File Naming Convention

<number>-<simplified-title>.py
<number>-<simplified-title>.md

Examples:

258-add-digits.py
001-two-sum.md

Example Usage (root/new.ps1)

# 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"

Python Solution Structure

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

LeetCode Commandments

  1. 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.
  2. Analyze constraints first — Input size and limits indicate the intended algorithm and whether brute force is viable.
  3. Use examples as a guide — Expand the given examples and create additional ones to uncover hidden patterns.
  4. Solve the simpler version first — Reduce the problem to its core; scale up only after the logic is clear.
  5. Optimize in phases — Start with correctness, then improve performance; don’t force an optimal solution immediately.
  6. Explain your thinking — Clear reasoning exposes gaps and aligns with interview expectations.
  7. Recognize patterns — Label each solved problem by pattern (hashing, two pointers, DP, BFS, etc.) to strengthen intuition.
  8. Review after solving — Study official or community solutions and extract at least one new insight.
  9. Re-solve deliberately — Revisit problems after 1 day, 1 week, and 1 month to reinforce long-term retention.
  10. Prioritize mastery over volume — Deep understanding of fewer problems leads to stronger overall performance.

Problem-Solving Procedure

1. Restate the problem

Summarize the task in one or two sentences. Clarify what must be computed and under what conditions.

2. Identify inputs and outputs

  • 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

3. Work through examples manually

  • Simulate each provided example step by step
  • Create at least one additional example
  • Confirm you understand how the correct output is produced

4. Identify patterns or rules

  • Look for repeated behavior in examples
  • Identify key relationships
  • Map the problem to known patterns when possible

5. Choose the algorithmic structure

  • Decide the high-level strategy
  • Write clear pseudocode
  • Ensure the pseudocode aligns with observed rules

6. Translate pseudocode to code

  • Implement step by step in Python
  • Keep implementation simple
  • Use descriptive variable names

7. Test the implementation

  • Test all provided examples
  • Add edge cases
  • Verify correctness before optimizing

8. Explore alternatives

  • Compare different viable approaches
  • Note trade-offs and when each alternative is preferred

9. Analyze complexity

  • Identify time complexity
  • Identify space complexity
  • Ensure the solution meets problem constraints

10. Reflect and reinforce

  • Summarize the pattern used
  • Note any confusions and how they were resolved
  • Consider adding the concept to spaced-repetition practice

Resources

Recommended Problems

Hash

Easy – Learning

Medium – Practice

Hard – Mastery

  • 146. LRU Cache — classic design problem using hashmap + linked list

Two Pointers

Easy – Learning

Medium – Practice

Hard – Mastery

Sliding Window

Easy – Learning

Medium – Practice

Hard – Mastery

Binary Search

Easy – Learning

Medium – Practice

Hard – Mastery

Greedy

Easy – Learning

Medium – Practice

Hard – Mastery

  • 135. Candy — non-trivial two-pass greedy construction

Sorting

Easy – Learning

Medium – Practice

Hard – Mastery

Heaps

Easy – Learning

Medium – Practice

Hard – Mastery

Monotonic Stack

Easy – Learning

Medium – Practice

Hard – Mastery

BFS

Easy – Learning

Medium – Practice

Hard – Mastery

DFS

Easy – Learning

Medium – Practice

Hard – Mastery

Dynamic Programming

Easy – Learning

Medium – Practice

Hard – Mastery

Backtracking

Easy – Learning

Medium – Practice

Hard – Mastery

Other Tips

Input array is sorted

  • Use binary search for efficient lookups
  • Use two pointers for pair-sum, window, or convergence patterns

Problems requiring all permutations or subsets

  • Use backtracking to generate all combinations, subsets, or permutations

Tree problems

  • Use DFS for depth-focused traversal or recursive structural checks
  • Use BFS for level-order traversal or shortest-path–style logic

Graph problems

  • Use DFS to explore connected components or detect cycles
  • Use BFS for shortest path in unweighted graphs or layer-based exploration

Linked list problems

  • Use two pointers for fast/slow traversal, cycle detection, or middle-finding

When recursion is not allowed

  • Use a stack to simulate recursive behavior manually

When the solution must be in-place

  • Swap values between indices to avoid extra storage
  • Reuse existing slots or encode multiple values in one place when possible

Maximum/minimum subarray or subset

  • Use dynamic programming for optimal substructure problems
  • Use a sliding window when the subarray is contiguous with monotonic constraints

Top/least K elements

  • Use a heap for efficient K-selection
  • Use QuickSelect for average-linear Kth-element selection

Common string or pattern problems

  • Use a hash map to count or compare frequencies
  • Use a trie for prefix-based queries or dictionary-style lookup

General fallback approaches

  • 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

About

Structured LeetCode practice template with numbered pattern folders, spaced-repetition review (Learning → One Day → One Week → One Month), and auto-generated .md/.py problem files. Designed for organized study, long-term mastery, and clean, repeatable workflows.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published