Coding Patterns in Python
Learn reusable DSA problem-solving techniques with illustrative Python examples.
Levels indicate concept complexity and prerequisites, not learner progress.
Beginner
- Recognising Coding Patterns — Choose a technique from the problem's rules rather than its name.
Intermediate
- Sliding Window — Reuse the work from one consecutive group when moving to the next. (shared from Data Structures and Algorithms · Intermediate)
- Two Pointers — Use two positions to make progress through an ordered row. (shared from Data Structures and Algorithms · Intermediate)
- Fast and Slow Pointers — Detect a linked-list cycle by moving at different speeds.
- Merging Intervals — Combine overlapping closed ranges without losing coverage.
- Cyclic Sort for Bounded Values — Place a permutation of 1 through n at its matching positions.
- In-Place Linked List Reversal — Reverse links while preserving the unvisited remainder.
- Tree Breadth-First Search — Visit a tree level by level using a queue.
- Tree Depth-First Search — Follow a branch before returning to its siblings.
- Building Subsets — Grow a power set by deciding whether to include each item.
- Modified Binary Search — Find the first matching position using a shrinking boundary.
Advanced
- Bitwise XOR for Paired Values — Cancel pairs to find one unpaired integer under a precise contract.
- Top K with a Min-Heap — Keep the k largest values seen so far without sorting the whole input.
- Priority Queues and Multiway Merge — Remove items by priority and combine several already sorted streams. (shared from Data Structures and Algorithms · Intermediate)
- Topological Sorting — Order tasks so each prerequisite appears before its dependent.
- Tries and Prefixes — Share character paths while distinguishing a word from a prefix.
- Dynamic Programming — Reuse overlapping subproblem answers to count step sequences.
Expert
- Combining Patterns and Proving Correctness — Combine sorting and two pointers while accounting for original positions and costs.
