| name | python-algorithm-cookbook |
| description | 4 algorithm patterns with full Python implementations for common coding problems |
| version | 1.0.0 |
| category | toolchain |
| author | Claude MPM Team |
| license | MIT |
| progressive_disclosure | {"entry_point":{"summary":"4 algorithm patterns: sliding window, BFS traversal, binary search, and hash map with full implementations","when_to_use":"When implementing algorithms for coding problems or optimizing data processing","quick_start":"Match your problem type to the right pattern: substring constraints -> sliding window, tree/graph -> BFS, sorted data -> binary search, O(1) lookup -> hash map"}} |
| context_limit | 700 |
| tags | ["python","algorithms","sliding-window","bfs","binary-search","hash-map","two-pointers","data-structures","complexity"] |
| requires_tools | [] |
Common Algorithm Patterns
Sliding Window (Two Pointers)
def length_of_longest_substring(s: str) -> int:
"""Find length of longest substring without repeating characters.
Sliding window technique with hash map to track character positions.
Time: O(n), Space: O(min(n, alphabet_size))
Example: "abcabcbb" -> 3 (substring "abc")
"""
if not s:
return 0
char_index: dict[str, int] = {}
max_length = 0
left = 0
for right, char in enumerate(s):
if char in char_index and char_index[char] >= left:
left = char_index[char] + 1
char_index[char] = right
max_length = max(max_length, right - left + 1)
return max_length