Skip to content

Collection of algorithmic patterns with explanations and multiple examples for each — from sliding window to greedy and prefix sums.

License

Notifications You must be signed in to change notification settings

ezpectus/Algorithm-patterns

Repository files navigation

Algorithm Patterns 📚🚀

This repository is my personal library of coding patterns — reusable algorithmic approaches that can be applied to solve multiple problems on platforms like LeetCode, Codeforces, HackerRank, or in real-world projects.

The main goal is to understand, memorize, and quickly recognize these patterns during problem-solving, instead of relying on random guesswork.


Why I Created This Repository 💡

I've solved hundreds of algorithmic problems, but noticed a repeating truth:

Many problems are just variations of the same core patterns.

The real skill isn't just solving one problem — it's recognizing the underlying technique instantly, and applying it in your own style.

This repo is designed to:

  • Build my personal algorithmic muscle memory 🧠
  • Document patterns with clear explanations
  • Provide multiple code implementations for each pattern
  • Categorize patterns for quick navigation
  • Create a long-term reference for myself and others

Structure 🗂️

Each pattern has:

  1. README section explaining:
    • When to use the pattern
    • Time/space complexity
    • Common pitfalls
  2. Example problems (3–5 per pattern)
  3. Solutions in C# (my main language), sometimes with Python/Java for comparison
  4. Pattern Variations if applicable

Example Pattern: Sliding Window

When to use:

  • Problems involving subarrays/substrings
  • Optimizing repeated range calculations
  • Fixed-size or dynamic ranges

Advantages:

  • Reduces O(n²) solutions to O(n)
  • Simplifies logic for continuous segments

Common mistakes:

  • Forgetting to update the window after moving pointers
  • Not handling edge cases (empty arrays, single elements)

Example Problems:

  • Find the maximum sum of k consecutive elements
  • Longest substring without repeating characters
  • Minimum size subarray sum

Categories 📋

  • Two Pointers
  • Sliding Window
  • Prefix Sum
  • Binary Search Patterns
  • Greedy
  • Dynamic Programming Templates
  • Graph Traversal (BFS/DFS)
  • Backtracking
  • Heap/Priority Queue
  • Hashing Tricks

How to Use This Repo 🛠️

  1. Pick a pattern from the list
  2. Read the theory & common use cases
  3. Go through the example problems
  4. Implement them without looking at the solution
  5. Compare with my solution & note any improvements

License 📜

This project is licensed under the MIT License — you are free to use, modify, and share the code, but please credit the author.


Future Plans 🚀

  • Expand examples for competitive programming
  • Add a "micro patterns" section (tiny reusable tricks)
  • Compare performance of different approaches for the same problem

About Me 👨‍💻

I'm a developer focused on mastering algorithms and data structures, not just for interview prep, but to be able to solve any problem from scratch, in my own way.
This repository is a key part of that journey.

About

Collection of algorithmic patterns with explanations and multiple examples for each — from sliding window to greedy and prefix sums.

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published