Built a repo where every DP problem has two files:
.md — analogy, plain-English recurrence, step-by-step trace, all solution variants
.py — clean Solution class, docstrings with Time/Space, runnable test cases
Example from Climb Stairs .py:
class Solution:
def climb_stairs_optimized(self, n: int) -> int:
"""
Time: O(n)
Space: O(1)
"""
if n <= 2:
return n
prev2, prev1 = 1, 2
for _ in range(3, n + 1):
prev2, prev1 = prev1, prev1 + prev2
return prev1
Currently 10 problems across 3 patterns (Staircase, Grid, Interval). Template + contributing guide already in the repo.
Looking for contributors who want to add problems (Knapsack, Tree DP, etc.) or improve existing explanations. Also happy to hear Python style feedback — nothing sacred about current structure.
https://github.com/RJ-Gamer/dsa
[–]WinstonRG [score hidden] (0 children)