Citadel SDE Intern OA 在量化金融公司裡屬於**「題面看著簡單,但每題都隱含 1-2 個邊界陷阱」的代表。HackerRank 上的 3 道題——Price Check 價格錯誤統計、Framing Text 矩形文字框、Recommendation System 共同好友推薦——每道題 LeetCode Easy~Medium,但 Citadel 評分系統對字串格式精確度和邊界完整性的要求是金融科技公司裡最嚴苛的之一**。本文給出 2026 實習 OA 三道原題的完整 Python AC 解、複雜度分析與隱藏 case 防禦。
Citadel SDE Intern OA 概覽
| 維度 | 詳情 |
|---|---|
| 平台 | HackerRank for Work |
| 時長 | 70 分鐘 |
| 題量 | 3 道 |
| 難度 | LeetCode Easy ~ Medium |
| 通過率 | 約 25-30% |
| 投遞崗位 | Citadel SDE Intern / Citadel Securities SDE Intern |
題目一:Price Check(價格錯誤統計)
題目描述
商店收銀員手動輸入商品價格,可能出錯。給定:
products[n]:商品名列表productPrices[n]:商品的正確價格productSold[m]:實際售出的商品名列表soldPrice[m]:實際錄入的售價列表
返回錄入錯誤的次數。
示例:
products = ['eggs', 'milk', 'cheese']
productPrices = [2.89, 3.29, 5.79]
productSold = ['eggs', 'eggs', 'cheese', 'milk '] # 注意第 4 項尾隨空格
soldPrice = [2.89, 2.99, 5.79, 3.29]
錯誤數 = 2 (eggs 第 2 次賣錯,cheese 價格不對)
解題思路
構建 name → price 字典,逐項比對。Citadel 的隱藏 case 重點在:
- 商品名帶前後空格(如
"milk ")需要.strip() - 浮點比較精度:用
abs(a - b) < 1e-2而非== - 未知商品(productSold 中出現 products 裡沒有的名字):題目期望「算作錯誤」
Python 完整解法
from typing import List
def price_check(
products: List[str],
product_prices: List[float],
products_sold: List[str],
sold_prices: List[float],
) -> int:
catalog = {p.strip(): pr for p, pr in zip(products, product_prices)}
errors = 0
for name, price in zip(products_sold, sold_prices):
key = name.strip()
if key not in catalog:
errors += 1
elif abs(catalog[key] - price) > 1e-2:
errors += 1
return errors
時間複雜度:O(n + m)
空間複雜度:O(n)
Citadel 隱藏 case
| 輸入 | 期望 |
|---|---|
| productSold 含未知商品 | 算 1 個錯誤 |
| 商品名大小寫不同 | 視為不同商品 |
| 浮點小誤差(差 0.001) | 不算錯誤 |
題目二:Framing Text(矩形文字框)
題目描述
接收一行多個單詞的字串,輸出按「一詞一行」格式的矩形框,每個單詞左右各留 1 空格。
示例輸入:
"Hello World in a frame"
示例輸出:
+-------+
| Hello |
| World |
| in |
| a |
| frame |
+-------+
解題思路
- 找到最長單詞長度
L - 框寬度 =
L + 4(|+ 單詞 + 右側空格補齊 +|) - 每個單詞左對齊 + 右側空格補齊
Python 完整解法
def print_boxed_text(s: str) -> str:
words = s.split()
if not words:
return ""
max_len = max(len(w) for w in words)
border = "+" + "-" * (max_len + 2) + "+"
lines = [border]
for w in words:
padded = w.ljust(max_len)
lines.append(f"| {padded} |")
lines.append(border)
return "\n".join(lines)
時間複雜度:O(n × L)
空間複雜度:O(n × L)
Citadel 隱藏 case
| 輸入 | 期望 |
|---|---|
"" 空字串 |
返回空字串(不要列印邊框) |
| 多空格分隔 | split() 預設按任意空白分割 |
| 單個單詞 | 正常輸出單行 |
| 單詞全是同一長度 | 邊框寬度 = 單詞長度 + 4 |
評分點:Citadel 對輸出末尾換行敏感——返回字串末尾不要多餘 \n,否則 hidden test 失敗。
題目三:Recommendation System(共同好友推薦)
題目描述
社交網路有 n 個使用者(編號 0 到 n-1),m 對好友關係。為每個使用者推薦共同好友最多的、當前不是好友的另一使用者。如果有平局,選 index 最小的。如果沒有候選,返回 -1。
示例:
n = 5
friendships = [[0,1], [0,2], [1,3], [2,3], [3,4]]
| 使用者 | 已是好友 | 候選 | 共同好友 | 推薦 |
|---|---|---|---|---|
| 0 | {1, 2} | {3, 4} | 0&3 共同 {1,2}, 0&4 共同 {3} | 3 |
| 1 | {0, 3} | {2, 4} | 1&2 共同 {0,3}, 1&4 共同 {3} | 2 |
| 2 | {0, 3} | {1, 4} | 2&1 共同 {0,3}, 2&4 共同 {3} | 1 |
| 3 | {1, 2, 4} | {0} | 3&0 共同 {1,2} | 0 |
| 4 | {3} | {0,1,2} | 4&0 共同 {3}, 4&1 共同 {3}, 4&2 共同 {3} | 0 |
輸出:[3, 2, 1, 0, 0]
解題思路
每個使用者用 set 存好友。對每個使用者 i:
- 遍歷所有候選使用者 j(不為 i,且不為 i 的好友)
- 計算
len(friends[i] & friends[j]) - 取最大且 j 最小
Python 完整解法
from typing import List
def recommend(n: int, friendships: List[List[int]]) -> List[int]:
friends = [set() for _ in range(n)]
for a, b in friendships:
friends[a].add(b)
friends[b].add(a)
result: List[int] = []
for i in range(n):
best_j = -1
best_count = -1
for j in range(n):
if j == i or j in friends[i]:
continue
count = len(friends[i] & friends[j])
if count > best_count or (count == best_count and j < best_j):
best_count = count
best_j = j
if best_count <= 0:
result.append(-1)
else:
result.append(best_j)
return result
時間複雜度:O(n² × avg_degree)
空間複雜度:O(n + m)
Citadel 隱藏 case
| 輸入 | 期望 |
|---|---|
| 使用者沒有任何好友 | 返回 -1(無法計算共同好友) |
| 所有候選都 0 共同好友 | 返回 -1 |
自環 [i, i] |
題目通常不會給,但程式碼用 j == i 排除 |
| 重複好友對 | set 自動去重 |
Citadel 這道題的「狠」在於「0 共同好友 = -1」——不是返回 index 0 的候選使用者。隱藏 case 至少有 1 個空圖測試。
Citadel SDE Intern OA 通過策略
1)70 分鐘分配
| 題目 | 建議時間 |
|---|---|
| Price Check | 10 分鐘 |
| Framing Text | 15 分鐘 |
| Recommendation System | 30 分鐘 |
| 留 buffer 除錯 | 15 分鐘 |
2)字串處理優先級
Citadel 評分對字串格式嚴格匹配——前後空格、大小寫、末尾換行都計較。提交前用 repr() 列印輸出,目視檢查。
3)Recommendation System 不必追求 O(n log n)
n 通常 ≤ 1000,O(n²) 即可 AC。不要為了最佳化引入新 bug。
FAQ
Citadel SDE Intern OA 通過率多少?
約 25-30%。Citadel 是量化金融崗位中OA 難度中等但通過率最低的公司之一——主要原因是履歷篩選已經非常嚴,進入 OA 的候選人都是 top 院校 + 高 GPA。
這 3 道題在 2026 還會出嗎?
會。Price Check 和 Framing Text 是 Citadel 題庫長青題目,2024-2026 反覆出現。Recommendation System 在 2026 實習季出現率約 40%,與 Process Allocation / Load Balancing 題型輪換。
Citadel HackerRank 允許跳題嗎?
允許,但強烈建議按順序做——Price Check 是 warm-up,做完心態穩。直接做 Recommendation System 容易超時。
OA 之後多久收到 onsite 邀請?
平均 3-5 個工作日。Citadel 速度比 JPMorgan / Goldman Sachs 快很多——快速決策是 Citadel 招聘文化的特點。
Citadel SDE Intern 和 Citadel Securities SDE Intern 的 OA 一樣嗎?
不一樣。Citadel(hedge fund 主體)的 OA 偏演算法 + 資料結構;Citadel Securities(market making)的 OA 多 1 道做市機率題或Pandas 資料處理題。
正在準備 Citadel SDE Intern OA?
oavoservice 提供 Citadel / Citadel Securities / Two Sigma / Jane Street / HRT 等量化金融公司 OA 全流程輔助:題型分類、隱藏 case 防禦、Python 實戰程式碼模板。我們的導師包括前 Citadel quant developer,對 Citadel 的「字串嚴格匹配」評分風格有專門應對策略。
立即加入微信:Coding0201,獲取 Citadel OA 一對一輔導。
#Citadel #CitadelOA #SDEIntern #HackerRank #量化金融 #OA真題
聯絡方式
Email: [email protected]
Telegram: @OAVOProxy