Python DSA — Senior Level
Hard patterns that separate senior engineers in FAANG and product company interviews. Two pointers, sliding window, recursion, stacks, queues, binary search, and dynamic programming.
Two pointers on a sorted array — O(n) without extra space. The purest two-pointer problem to start with.
Sort + two pointers inside a loop — O(n²) with deduplication. The two-pointer pattern extended to triplets.
Greedy two-pointer shrink from both ends — a classic area maximization problem.
Sort + greedy two-pointer (heaviest + lightest) — two-pointer as a greedy pairing strategy.
Sliding window with a set — expand right, shrink left on duplicate. The canonical sliding window intro.
Sliding window with a budget (k flips) — window shrinks when budget is exhausted. Core pattern.
Shrinkable sliding window — expand until sum ≥ target, then shrink. Variable-size window pattern.
Fixed-size sliding window with frequency match — the window has constant length equal to pattern length.
Prefix sum + hash map — count subarrays summing to k in O(n). Not solvable with plain sliding window.
Monotonic stack — maintain a stack of decreasing indices, pop when a warmer day is found.
Stack simulation with conditional pop — complex push/pop logic. Tests stack mastery beyond bracket matching.
Stack for nested structure — push current string + count, build inner, then pop and multiply. Recursion-like.
Sort by start + greedy merge — the canonical interval problem. Foundational for calendar and schedule questions.
Binary search twice — left boundary and right boundary separately. The binary search extension pattern.
Binary search with an extra condition to determine which half is sorted — classic binary search variation.
Counter + min-heap of size k — O(n log k). The heap pattern for top-N queries.
DP with two choices per step: rob or skip — dp[i] = max(dp[i-2] + val, dp[i-1]). Classic 1D DP intro.
Bottom-up DP with unbounded choices — dp[amount] = min coins. The textbook unbounded knapsack template.
Two-pointer with prefix max — O(n) space reduction from the prefix array approach. A must-solve hard problem.
Sliding window with two frequency maps and a match counter — the hardest sliding window pattern.