Imagine you're designing an event bus for an e-commerce platform handling 500M daily events: orders, payments, inventory changes, shipping updates. Your architect asks: "Kafka or SQS?"
Kafka is a big recorder everyone can rewind. SQS is a courier who delivers once and leaves. Kinesis is the AWS recorder — easier but pricier. RabbitMQ is a post office with precise routing.
算法 — #323 Number of Connected Components in an Undirected Graph
Algorithms — #323 Number of Connected Components (Medium) — Graphs
Day 114 · Pattern Block: 图遍历 (11/13) · Expert Phase
💻 算法 / Algorithms
🧩 图遍历模式 (11/13) — building on the BFS/DFS template from the Graphs block
你在 LinkedIn 后端工作。数据库里有 n 个用户和他们的好友关系。现在要回答:总共有多少个"互不相连的朋友圈"?
You work at LinkedIn. Given n users and friendship edges, how many disconnected "social clusters" exist?
🧩 模式变体分析 / Pattern Variation
这道题是 Graph Valid Tree (#261) 的延伸:
Tree: exactly 1 component + no cycle
今天: count all components (don't care about cycles)
两种解法都完美映射到模板:
解法1: Union-Find (最优)
class UnionFind:
def __init__(self, n):
self.parent = list(range(n)) # each node is its own root
self.rank = [0] * n
self.components = n # start: n separate componentsdef find(self, x):
# path compressionif self.parent[x] != x:
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def union(self, x, y):
px, py = self.find(x), self.find(y)
if px == py:
return# already connected# union by rankif self.rank[px] < self.rank[py]:
px, py = py, px
self.parent[py] = px
if self.rank[px] == self.rank[py]:
self.rank[px] += 1
self.components -= 1# merged two → one fewer componentdef countComponents(n, edges):
uf = UnionFind(n)
for u, v in edges:
uf.union(u, v)
return uf.components
解法2: DFS (直接用模板)
def countComponents(n, edges):
# Build adjacency list
graph = [[] for _ in range(n)]
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
visited = set()
count = 0def dfs(node):
visited.add(node)
for neighbor in graph[node]:
if neighbor notin visited:
dfs(neighbor) # explore entire componentfor node in range(n):
if node notin visited:
dfs(node) # new unvisited node = new component
count += 1return count
You have toy blocks. Some are glued together. Count the separate groups. Each time you glue two blocks: if they're already in the same group, nothing changes; otherwise group count decreases by 1.
Staff Engineer Promotion: Do Your Behavioral Patterns Match?
🎯 场景 / Scenario
面试官说:"Tell me about your most impactful technical contribution in the last 2 years."
这道题考的不是技术细节——考的是你如何定义影响力。
This question isn't about technical details — it's about how you define impact.
📐 Staff vs Senior: 关键区别 / Key Distinction
Senior Engineer Impact:
我设计了一个系统,性能提升 10x
"I designed a system that improved performance 10x"
→ Individual contribution, clear ownership
Staff Engineer Impact:
我重新定义了团队的架构决策框架,
使 6 个下游团队的系统设计评审时间缩短 60%,
并在公司范围内推广了这一方法论
"I redefined how architecture decisions are made,
cutting design review time by 60% for 6 downstream teams
and scaling the methodology company-wide"
→ Organizational multiplier, ambiguous ownership = harder, more valued
"I built the service mesh that handles 99.99% of our traffic."
✅ Staff 回答:
"I identified that we had 12 teams making incompatible infrastructure choices. I built consensus on a shared service mesh, wrote the migration playbook, and personally unblocked the 3 teams that were stuck. Today all 12 teams run on the same foundation — and I'm no longer needed to maintain it."
关键词: identified, built consensus, unblocked others, no longer needed
A Senior engineer is a great problem-solver. A Staff engineer is the one who defines which problems matter — and makes the whole team better at solving them.
AI 综合 — RAG + 向量数据库 + 结构化输出的完整生产流水线
AI Synthesis — Full Production Pipeline: RAG + Vector DB + Structured Output
Day 114 · Synthesis Mode · Expert Phase
🤖 AI
把学过的 AI 概念串成一条生产级流水线
Connecting Learned AI Concepts into a Production-Grade Pipeline
🎯 场景 / Scenario
你要构建一个企业内部知识库问答系统:上传文档 → 自动索引 → 用户提问 → AI 返回结构化答案(含来源引用)。
Build an internal enterprise Q&A system: upload docs → auto-index → user asks → AI returns structured answer with citations.
把文档变成数字向量存起来(就像给每段话拍了一张"语义指纹")。用户提问时,找出最相似的几段话,让 AI 读这几段话来回答——而不是靠记忆瞎猜。
Turn documents into number vectors (like semantic fingerprints). When a user asks, find the most similar passages and have the AI answer from those — not from memory or guesswork.
Attention Heatmap
When the model processes it, it attends most strongly to animal.