🔄 复习日 / Review Day — Day 140
📊 NeetCode: 109/150 · SysDesign: 60/40 · Behavioral: 60/40 · Frontend: 37/50 · AI: 30/30
今天是复习日!回顾过去4天的内容(Coin Change, Max Product Subarray, Word Break, LIS + 系统设计 / Soft Skills / AI)。
📝 Quick Quiz — 3 Mini-Reviews
Q1: [💻 Algorithms] In the past 4 days you covered four 1-D DP problems: Coin Change, Maximum Product Subarray, Word Break, and LIS. All use dp[i] but the type and transition differ. Explain the key difference between Coin Change's transition and Word Break's transition — and why Word Break's dp[i] is a boolean instead of an integer.
<details><summary>显示答案 / Show Answer</summary>
Coin Change: dp[i] = min(dp[i - coin] + 1) — dp[i] is an integer representing the minimum number of coins to make amount i. Each transition looks backward by a fixed coin value and takes the minimum.
Word Break: dp[i] = any(dp[j] and s[j:i] in word_set for all j < i) — dp[i] is a boolean ("can the first i characters be segmented?"). The transition scans all split points j < i, not just fixed-step lookbacks. One valid witness (dp[j]=True and s[j:i] in dict) is enough to set dp[i]=True.
Key insight: dp[i] doesn't have to be a number. When the subproblem answer is "possible or not," use bool. When you want "how many ways," use int. When you want "all ways," use list — this is exactly what Word Break II (#140) does. The pattern template is the same; only the value type and aggregation (min, max, any, sum) change.
</details>
Q2: [🏗️ System Design] A startup is building a B2B SaaS product and asks you: "Should we put all tenants in one shared Postgres database with a tenant_id column, or give each tenant their own database?" Walk through the three multi-tenancy patterns and the decisive factor for choosing between them.
<details><summary>显示答案 / Show Answer</summary>
Pattern A — Shared Everything (Pool): Single DB, tenant_id on every table. Cheapest to operate, easiest to deploy. Problem: noisy-neighbor (one tenant's heavy query hurts others), and compliance requirements (GDPR right-to-erasure, data residency) are hard to satisfy.
Pattern B — Shared App, Isolated DB (Bridge): Same app servers route queries to per-tenant DBs (or per-shard). Blast radius is bounded (one tenant's DB issue doesn't affect others), and per-tenant backup/restore is easy. Downside: schema migrations must fan out to every tenant DB.
Pattern C — Silo (Dedicated): Each tenant gets their own stack (app + DB + cache). Maximum isolation and compliance, but expensive and operationally complex. Best for enterprise/regulated customers who pay for it.
Decisive factor: Start with Pattern A. Move to Pattern B when you land enterprise customers or face compliance audits. Move to Pattern C only if you offer a "dedicated tier" at a significant price premium. The system design principle: match isolation level to the customer's risk/compliance requirements and willingness to pay.
</details>
Q3: [🤖 AI] Based on the AI news from Day 139: Mistral Large 4 ("Le Chonk") reportedly has 1 trillion parameters but activates only ~49B per token. What architectural technique enables this? And why does this matter economically for large model deployment?
<details><summary>显示答案 / Show Answer</summary>
Mixture of Experts (MoE): Instead of activating all parameters for every token, an MoE model has many "expert" sub-networks and a learned router that selects a small subset of experts (e.g., top-2 out of 64) per token. Only those activated experts participate in the forward pass.
Why it matters economically: Inference compute cost scales with activated parameters, not total parameters. A 1T parameter MoE that activates 49B per token costs roughly the same to run as a 49B dense model — but can have the capacity (knowledge storage, task specialization) of a much larger model. This makes trillion-parameter models economically viable to serve at scale without requiring proportionally larger GPU clusters.
The tradeoff: MoE models require more total memory to store all expert weights, and routing decisions add coordination overhead. They also risk "expert collapse" if training isn't carefully tuned. But for inference throughput at scale, the activated-parameter efficiency is a major win — which is why GPT-4, Gemini 1.5, and now Mistral Large 4 all reportedly use MoE architectures.
</details>
💡 复习巩固记忆,螺旋式上升。
📅 明天继续新内容!