15 must-know problems, Python essentials, AI agent patterns β everything you need in one page.
Click any card to reveal the solution, complexity, and key insights
mid = (left + right) // 2. Floor division important.dp[i] = min(dp[i], dp[i-coin]+1).Recognize the pattern, apply the template
| Pattern | When to Use | Key Data Structure | Problems |
|---|---|---|---|
| Hash Map | Need O(1) lookup, counting, grouping | dict |
Two Sum, Valid Anagram, Group Anagrams |
| Two Pointers | Sorted array, find pairs, palindromes | Pointer indices | Two Sum II, Merge Sorted Lists |
| Sliding Window | Contiguous subarray/substring optimization | set or dict |
Longest Substring Without Repeating |
| Stack | Matching brackets, nested structure, undo | list as stack |
Valid Parentheses |
| Binary Search | Sorted array, find target, minimize/maximize | Pointer indices | Binary Search |
| Dynamic Programming | Overlapping subproblems, optimal substructure | list (dp array) |
Climbing Stairs, Coin Change, Max Subarray |
| DFS / BFS | Graph traversal, connected components, paths | Recursion / Queue | Number of Islands |
| Linked List | In-place reversal, merge, cycle detection | Node pointers | Reverse List, Merge Two Lists |
Essential syntax and patterns for coding interviews
len(s)s[0:5] Reverse: s[::-1]s.split() Join: '-'.join(list)'hello' in sf"Hi {name}"s.upper(), s.lower()[1, 2, 3] Last: arr[-1]arr[1:3], arr[:3], arr[2:].append(x) Remove last: .pop().insert(idx, val)sorted(arr) (new) vs arr.sort() (in-place)3 in arr{'a': 1, 'b': 2}d.get('key', 0) β avoids KeyErrordel d['key']d.keys(), d.values(), d.items()'key' in dcount[x] = count.get(x, 0) + 1{1, 2, 3} Empty: set()s.add(4) Remove: s.discard(3)4 in s β O(1) lookup!s1 | s2 Intersect: s1 & s2s1 - s2range(5) β 0,1,2,3,4range(0, 10, 2) β 0,2,4,6,8for i, val in enumerate(arr):for a, b in zip(list1, list2):[x*2 for x in range(5)]{x: x*2 for x in range(5)}float('inf') and float('-inf')collections.Counter("hello") β freq mapcollections.defaultdict(list)collections.deque() β O(1) both endsheapq.heappush(h, x) β min-heapsorted(arr, key=lambda x: x[1])a, b = b, ax if condition else y6 progressive agent implementations β from basics to production
# Tools as Python functions
tools = {"calculator": calc, "weather": weather}
def simple_agent(question):
tool = pick_tool(question) # keyword match
return tools[tool](question)
# 3 API calls in 1s (parallel) vs 3s (serial)
results = await asyncio.gather(
fetch_supplier("SUP-001"),
fetch_inventory("ITEM-123"),
fetch_price("ITEM-123")
)
asyncio.gather() for parallel calls + Pydantic for validation# Server registers tools
server.register_tool("search", desc, fn)
# Client discovers & calls
tools = client.discover_tools()
result = client.use_tool("search", args)
# ReAct loop
Step 1: THOUGHT β decide what to do
Step 2: ACTION β pick & call a tool
Step 3: OBSERVE β see the result
Step 4: Repeat or return answer
# LLM picks the tool (not keywords!)
response = openai.chat(
messages=[{"role": "user", "content": q}],
tools=tool_descriptions # JSON schema
)
# Execute tool LLM chose β send result back
# Trace spans for each step
with tracer.start_span("agent_query") as span:
span.set_attribute("question", q)
# Metrics: request count, latency p99, errors
Last-minute reminders before you walk in
[], "", None[1], "a"[5,5,5,5]// for integer division (not /)True/False/None are capitalizedlist.sort() returns None!range(n) goes 0 to n-1is vs == (identity vs equality)