feat(content): add categories and patterns

This commit is contained in:
2025-04-21 20:44:21 +01:00
parent 2f0e2a40a6
commit e4a71ade59
2 changed files with 189 additions and 0 deletions

View File

@@ -0,0 +1,129 @@
patterns:
- name: Two Pointers
slug: two-pointers
description: Use two pointers to traverse data from different positions, often moving toward or away from each other.
when_to_use: |
- Sorted arrays where you need to find pairs
- Linked list cycle detection
- Removing duplicates in-place
- Partitioning arrays
- Palindrome checking
- name: Sliding Window
slug: sliding-window
description: Maintain a window of elements that slides through the data, tracking a constraint or computing aggregates.
when_to_use: |
- Finding subarrays/substrings with specific properties
- Maximum/minimum sum of fixed-size windows
- Longest substring with at most K distinct characters
- Problems mentioning "contiguous" elements
- name: Fast & Slow Pointers
slug: fast-slow-pointers
description: Two pointers moving at different speeds, commonly used for cycle detection.
when_to_use: |
- Detecting cycles in linked lists or arrays
- Finding the middle of a linked list
- Finding the start of a cycle
- Happy number problem
- name: Binary Search
slug: binary-search
description: Efficiently search sorted data by repeatedly dividing the search space in half.
when_to_use: |
- Sorted arrays or search spaces
- Finding boundaries (first/last occurrence)
- Searching in rotated sorted arrays
- Finding peak elements
- Minimizing/maximizing with monotonic constraints
- name: BFS (Breadth-First Search)
slug: bfs
description: Level-by-level traversal using a queue, optimal for shortest paths in unweighted graphs.
when_to_use: |
- Shortest path in unweighted graphs
- Level-order tree traversal
- Finding all nodes at distance K
- Word ladder problems
- Matrix traversal
- name: DFS (Depth-First Search)
slug: dfs
description: Explore as deep as possible before backtracking, using recursion or a stack.
when_to_use: |
- Tree/graph traversal
- Path finding
- Detecting cycles
- Topological sorting
- Connected components
- Backtracking problems
- name: Backtracking
slug: backtracking
description: Build solutions incrementally, abandoning paths that fail to satisfy constraints.
when_to_use: |
- Generating all permutations/combinations
- Sudoku solver
- N-Queens problem
- Subset/partition problems
- Word search in grid
- name: Dynamic Programming
slug: dynamic-programming
description: Break problems into overlapping subproblems, storing results to avoid recomputation.
when_to_use: |
- Optimization problems (min/max)
- Counting problems
- Problems with optimal substructure
- Sequence alignment
- Knapsack-type problems
- name: Greedy
slug: greedy
description: Make locally optimal choices at each step, hoping for a global optimum.
when_to_use: |
- Interval scheduling
- Huffman coding
- Minimum spanning tree
- Activity selection
- When local optimum leads to global optimum
- name: Monotonic Stack
slug: monotonic-stack
description: Stack maintaining elements in sorted order, used for next greater/smaller element problems.
when_to_use: |
- Next greater/smaller element
- Largest rectangle in histogram
- Daily temperatures
- Stock span problem
- Trapping rain water
- name: Heap / Priority Queue
slug: heap
description: Data structure for efficiently finding min/max elements.
when_to_use: |
- Top K elements
- K-way merge
- Median from data stream
- Task scheduling
- Dijkstra's algorithm
- name: Union Find
slug: union-find
description: Track disjoint sets with efficient union and find operations.
when_to_use: |
- Connected components in graphs
- Cycle detection in undirected graphs
- Kruskal's minimum spanning tree
- Social network connections
- Accounts merge
- name: Trie
slug: trie
description: Tree-like data structure for efficient string prefix operations.
when_to_use: |
- Autocomplete systems
- Word dictionary with wildcard search
- Longest common prefix
- Word break problems
- Spell checker