Hash map counting
Anagrams, two-sum, longest substring without repeats.
from collections import Counter
Counter("anagram") == Counter("nagaram") # TruePared down to what real interviews ask. 8 algorithmic patterns + 5 system-design lite questions + STAR shape. Not a 200-problem LeetCode plan.
Anagrams, two-sum, longest substring without repeats.
from collections import Counter
Counter("anagram") == Counter("nagaram") # TrueSorted-array merge, palindrome check, container-with-water.
l, r = 0, len(s) - 1
while l < r:
if s[l] != s[r]: return False
l += 1; r -= 1Longest substring, max-sum k window, anagrams of P in S.
l = best = 0
seen = set()
for r, c in enumerate(s):
while c in seen: seen.discard(s[l]); l += 1
seen.add(c)
best = max(best, r - l + 1)Valid parens, daily temperatures, evaluate RPN.
stack = []
for c in s:
if c in "([{": stack.append(c)
elif not stack or pair(stack.pop()) != c: return False
return not stackLevel-order, number-of-islands, course-schedule.
from collections import deque
q = deque([start]); seen = {start}
while q:
node = q.popleft()
for nb in graph[node]:
if nb not in seen:
seen.add(nb); q.append(nb)Top-K, kth largest, merge K sorted lists.
import heapq
h = []
for x in nums:
heapq.heappush(h, x)
if len(h) > k: heapq.heappop(h)Min in rotated array, capacity to ship in D days.
lo, hi = 1, max(weights)
while lo < hi:
mid = (lo + hi) // 2
if feasible(mid): hi = mid
else: lo = mid + 1Longest-common, knapsack, coin-change, edit distance.
# Bottom-up coin change
dp = [float("inf")] * (amount + 1); dp[0] = 0
for a in range(1, amount + 1):
for c in coins:
if c <= a: dp[a] = min(dp[a], dp[a - c] + 1)Situation → Task → Action → Result. Numbers in Result.
# "Latency p95 was 480ms (S). Need <200ms before launch (T). Replaced the # synchronous Stripe call with a Celery write-behind queue (A). Hit 92ms # p95 in load tests, shipped on time (R)."
Have 3 stories memorised — one each for: challenge, conflict, ownership.
# Each story 60–90s spoken. Stick to one project per story.
Skip these — they're tells.
# - "I worked hard" → no Action specificity # - "We did X" → no individual ownership # - "I learned a lot" → no Result # - silence > 4s → start narrating, even mid-thought
Hash → DB lookup. Don't over-engineer.
# Snowflake-style ID → base62 slug. Cache slug→URL in Redis. # Rate-limit POSTs per IP.
Token bucket vs sliding window — be able to sketch both.
# Sliding window via Redis Lua: ZADD timestamps + ZREMRANGEBYSCORE + ZCARD.
Async queue + retries + dedup.
# Celery worker per channel. Idempotency key per notification. # DLQ for poison messages.
Conflict resolution — last-write-wins or CRDT?
# Last-write-wins: include `updated_at`. Server keeps latest. # Mention CRDTs for "real" sync.
Cursor, not offset — page stable under inserts.
GET /feed?cursor=<created_at>&limit=20 # Response includes `next_cursor`.
Want to actually learn these patterns, not just paste them? Open the Python interview cheatsheet track — each snippet has a full lesson behind it.