Expected tosses to get HHH (and $n$ heads in a row) 抛出 HHH 的期望次数 (推广到 $n$ 个连续正面)
A fair coin is tossed repeatedly until the sequence $\text{HHH}$ (three heads in a row) appears. What is the expected number of tosses? Generalize to $n$ consecutive heads.
反复抛一枚均匀硬币, 直到出现 $\text{HHH}$ (连续三个正面). 期望抛掷多少次? 并将结果推广到 $n$ 个连续正面.
The "every fail resets you" trick"一次反面就清零" 的小技巧
Let $E_n$ be the expected number of tosses to get $n$ heads in a row. Suppose you've already managed to get $n-1$ heads in a row (which took $E_{n-1}$ tosses on average). You toss one more coin:
设 $E_n$ 为得到 $n$ 个连续正面的期望抛掷次数. 假设你已经成功抛出 $n-1$ 个连续正面 (平均花费 $E_{n-1}$ 次). 再抛一次:
- With probability $\tfrac{1}{2}$: it's H → done in $E_{n-1}+1$ tosses.
- With probability $\tfrac{1}{2}$: it's T → you've used $E_{n-1}+1$ tosses and you're back at zero, so you need $E_n$ more.
- 概率 $\tfrac{1}{2}$: 正面 → 总共 $E_{n-1}+1$ 次完成.
- 概率 $\tfrac{1}{2}$: 反面 → 已用 $E_{n-1}+1$ 次, 但回到起点, 还需 $E_n$ 次.
Simplify:化简:
$$E_n = E_{n-1} + 1 + \tfrac{1}{2}E_n \;\;\Longrightarrow\;\; E_n = 2E_{n-1} + 2$$With $E_0 = 0$:由 $E_0 = 0$:
| $n$ | 1 | 2 | 3 | 4 | ⋯ | general通项 |
|---|---|---|---|---|---|---|
| $E_n$ | 2 | 6 | 14 | 30 | ⋯ | $2^{n+1}-2$ |
Why this beats the full state machine为什么比完整状态机更直观
The key observation: a tails always sends you back to state 0, no matter where you are. So you only track "how many H in a row do I currently have," and the recurrence collapses to one line. No 4-state system, no linear algebra.
关键观察: 反面永远把你打回状态 0, 不管你已连了几个正. 所以只需跟踪"当前连了几个正", 递推关系一行就能写完. 不需要 4 状态系统, 也不需要线性代数.
For probability $p$ of heads, the same logic gives $E_n = \dfrac{1-p^n}{p^n(1-p)}$. With $p=\tfrac{1}{2}$, $n=3$: $\dfrac{7/8}{1/16} = 14$. ✓
若正面概率为 $p$, 同样逻辑给出 $E_n = \dfrac{1-p^n}{p^n(1-p)}$. 代入 $p=\tfrac{1}{2}$, $n=3$: $\dfrac{7/8}{1/16} = 14$. ✓
Estimate $\pi$ via Monte Carlo 用 蒙特卡洛 估计 $\pi$
Design a Monte Carlo simulation that estimates the value of $\pi$. How would you implement the "is the point inside the circle" check?
设计一个蒙特卡洛模拟来估计 $\pi$ 的值. 如何实现 "判断点是否在圆内"?
Setup设置
Inscribe a quarter unit circle inside the unit square $[0,1]\times[0,1]$.
在单位正方形 $[0,1]\times[0,1]$ 内嵌一个四分之一单位圆.
- Area of square: $1$
- Area of quarter circle: $\dfrac{\pi}{4}$
- 正方形面积: $1$
- 四分之一圆面积: $\dfrac{\pi}{4}$
Random point & membership test随机点与判定
Draw $X \sim U(0,1)$ and $Y \sim U(0,1)$ independently. The point $(X,Y)$ lies inside the quarter circle iff its distance from the origin is $\leq 1$, i.e.
独立取 $X \sim U(0,1)$ 与 $Y \sim U(0,1)$. 点 $(X,Y)$ 在四分之一圆内当且仅当其到原点距离 $\leq 1$, 即
$$X^2 + Y^2 \leq 1$$(No square root needed — squaring both sides keeps it cheap.)
(不需要开平方 — 两边平方后判断更省算力.)
Estimator估计量
Run $N$ trials. Let $K$ be the number of points satisfying $X^2+Y^2 \leq 1$. Then by LLN:
运行 $N$ 次试验. 设 $K$ 为满足 $X^2+Y^2 \leq 1$ 的点数. 由大数定律:
$$\frac{K}{N} \xrightarrow{N\to\infty} \frac{\pi}{4} \quad\Longrightarrow\quad \hat{\pi} = 4 \cdot \frac{K}{N}$$Convergence rate (good follow-up to mention)收敛速度 (面试加分点)
Each trial is Bernoulli with $p = \pi/4$, so $K \sim \text{Bin}(N, \pi/4)$. The standard error is
每次试验是 $p=\pi/4$ 的伯努利, 故 $K \sim \text{Bin}(N, \pi/4)$. 标准误为
$$\text{SE}(\hat\pi) = 4 \sqrt{\frac{p(1-p)}{N}} \approx \frac{1.64}{\sqrt{N}}$$Pseudocode伪代码
import random N = 1_000_000 K = sum(1 for _ in range(N) if random.random()**2 + random.random()**2 <= 1) pi_hat = 4 * K / N
Probability of ~220 heads in 400 fair flips 400 次抛硬币得到 约 220 次 正面的概率
A fair coin is flipped 400 times. What is the probability of getting 220 heads? Treat both interpretations: "at least 220" and "exactly 220".
一枚均匀硬币抛 400 次. 得到 220 次正面的概率是多少? 分别讨论 "至少 220 次" 与 "恰好 220 次" 两种解读.
Frame the distribution先写出分布
Let $X$ = number of heads. Then $X \sim \text{Bin}(400, 0.5)$ with
设 $X$ = 正面次数. 则 $X \sim \text{Bin}(400, 0.5)$:
$$\mu = np = 200, \quad \sigma^2 = np(1-p) = 100, \quad \sigma = 10$$The exact $\binom{400}{220}/2^{400}$ is computable but useless in an interview. CLT to the rescue.
精确值 $\binom{400}{220}/2^{400}$ 算得出来但面试时没用. 这时该 CLT 上场.
Standardize标准化
$220$ is $\dfrac{220-200}{10} = 2$ standard deviations above the mean.
$220$ 距离均值 $\dfrac{220-200}{10} = 2$ 个标准差.
By 68-95-99.7, ~95% of mass is in $[-2, 2]$, so each tail has roughly $\dfrac{1-0.95}{2} = 2.5\%$.
由 68-95-99.7 法则, 约 95% 的质量在 $[-2, 2]$ 区间, 因此每条尾巴约 $\dfrac{1-0.95}{2} = 2.5\%$.
Interpretation A — "at least 220 heads"解读 A — "至少 220 次正面"
More precisely, $\Phi(-2) \approx 2.28\%$.更精确: $\Phi(-2) \approx 2.28\%$.
Interpretation B — "exactly 220 heads"解读 B — "恰好 220 次正面"
Continuity correction: $P(X=220) \approx P(219.5 < X < 220.5) = P(1.95 < Z < 2.05)$. Or use the local normal approximation $P(X=k) \approx \dfrac{1}{\sigma\sqrt{2\pi}} e^{-z^2/2}$ at $z=2$:
连续性修正: $P(X=220) \approx P(219.5 < X < 220.5) = P(1.95 < Z < 2.05)$. 或用局部正态近似 $P(X=k) \approx \dfrac{1}{\sigma\sqrt{2\pi}} e^{-z^2/2}$ ($z=2$):
$$P(X=220) \approx \frac{1}{10\sqrt{2\pi}} \cdot e^{-2} \approx \mathbf{0.54\%}$$Why "55%" is way off为什么 "55%" 错得离谱
55% only makes sense for $P(X \geq 200)$ — about half. But 220 is meaningfully above the mean: 20 extra heads is twice the standard deviation, deep into the tail. Always anchor on $\mu$ and count $\sigma$ away from it.
55% 只在 $P(X \geq 200)$ 时合理 — 大约一半. 但 220 显著高于均值: 多出 20 次正是 2 倍标准差, 已经深入尾部. 永远先锚定 $\mu$, 再数离它有几个 $\sigma$.
| $z$ | 1 | 1.65 | 2 | 2.33 | 3 |
|---|---|---|---|---|---|
| $P(Z>z)$ | 16% | 5% | 2.5% | 1% | 0.13% |
Why is credit-card interest higher than mortgage interest? 为什么信用卡利率比 房贷 利率高?
Credit cards typically charge ~20% APR while mortgages run ~6–7%. Explain the gap structurally.
信用卡 APR 通常约 20%, 房贷约 6–7%. 从结构上解释这一利差.
Anchor on the break-even rate先锚定盈亏平衡利率
The bank's break-even rate must cover its expected loss plus costs:
银行的盈亏平衡利率必须覆盖 预期损失 加上各项成本:
$$r \approx r_f + \text{term premium} + \text{credit spread} + \text{op costs} + \text{margin}$$Where credit spread is driven by
其中信用利差由如下公式驱动:
$$\text{Expected Loss} = \text{PD} \times \text{LGD} \times \text{EAD}$$PD = probability of default, LGD = loss given default, EAD = exposure at default.
PD = 违约概率, LGD = 违约损失率, EAD = 违约风险敞口.
Side-by-side逐项对比
| Factor因素 | Mortgage房贷 | Credit Card信用卡 |
|---|---|---|
| Collateral抵押物 | Yes — the house有 — 房屋本身 | None无 |
| LGD | ~20–25% (recover via foreclosure)~20–25% (止赎可回收) | ~80–100% (basically gone)~80–100% (基本拿不回) |
| PD | Low; full underwriting低; 全面尽调 (收入 / DTI / FICO) | Higher; lighter underwriting较高; 尽调宽松, 常被资金紧张者使用 |
| Loan size贷款规模 | Large, lumpy大额, 一次性 | Small, revolving — high servicing cost / $小额, 循环 — 单位金额服务成本高 |
| Tenor期限 | 15–30 yrs, fixed cash flows15–30 年, 固定现金流 | Open-ended, variable balance开放式, 余额变动 |
| Capital charge (Basel)资本占用 (巴塞尔) | Favorable risk weight优惠风险权重 | Punitive risk weight惩罚性风险权重 |
| Customer behavior客户行为 | Refinance shopping is common普遍比价, 易再融资 | Most carriers don't comparison shop大多数持卡人不会比价 |
Mortgage: PD = 1%, LGD = 20% → EL = 20 bps
Credit card: PD = 4%, LGD = 90% → EL = 360 bps
→ ~340 bps gap from credit risk alone, before operating costs. That accounts for most of the observed spread.
房贷: PD = 1%, LGD = 20% → EL = 20 bps
信用卡: PD = 4%, LGD = 90% → EL = 360 bps
→ 仅信用风险一项就贡献约 340 bps 利差, 还没算运营成本. 已能解释观察到的大部分利差.
Cheat sheet — what these are really testing 速查表 — 这些题真正在考你什么
| Q题号 | Surface topic表面话题 | What they actually want他们真正想看到的 |
|---|---|---|
| Q1 | Coin tosses抛硬币 | Recursion / first-step analysis递推 / 首步分析 |
| Q2 | $\pi$ estimation$\pi$ 估计 | Sampling, LLN, convergence rates采样, 大数定律, 收敛速度 |
| Q3 | Binomial probability二项概率 | CLT instinct when $n$ is large$n$ 大时立刻想到 CLT |
| Q4 | Banking trivia银行常识 | First-principles risk pricing从第一性原理出发的风险定价 |