最近剛幫一位同學拿下 Meta 26 SWE Intern OA ,四道 Codesignal 題全部 AC。說真的,這次的題風挺 Meta 的:不會給你特別 Hard 的演算法,但非常強調實現細節、模擬能力、邊界判斷。如果你還抱著“刷完 LeetCode 經典 100 題就能過”的想法,那麼你已經輸在了起跑線。

Q1 — Minimum Sum After One Operation
主題概觀
Given an array of positive integers nums, you may perform the following operation at most once:
Choose an index i and replace nums[i] with the sum of digits of nums[i].
Return the minimum possible total sum after performing zero or one operation.
示例
nums = [14, 7, 20]
替換 20 → 2 → 總和最小 → 29.
思路
這道題就是幫你熱下手:
- 原始總和先算出來
- 對每個數字算 digit sum
- “替換前後”做個差
- 貪心取最小即可
難度不大,就是典型 Codesignal Q1 的味道。
Q2 — Delivery System Using Drones
這題很有“Meta 產品模擬”的感覺,不是演算法難,而是步驟細。
主題概觀
Given a target distance and a list of station positions, you must deliver a package to the target using drones.
A drone can fly at most 10 units including the final hop.
You must always:
- 從當前點帶著貨物走到最近的 station
- 用 station 的無人機把貨物送出去(最多 10 units)
- 如果無人機沒飛到 target → 你要空手走過去拿貨物
- 重複直到送達 target
Return total distance with cargo.
關鍵點
Meta 非常喜歡這種“按題目給的步驟照寫就好”的題。
真正要注意的是:
- stations 要先 sort,否則會翻車
- 走路時,只有“帶著貨物”的距離才要累計
- 模擬步驟不要腦補,按題目順序來就萬無一失
總體是實現題,但細節一堆。
Q3 — Battery Usage Simulation
這題是典型 Codesignal 中等難度的“動態資源管理”。
主題概觀
You want to run your phone for total time t.
You have several batteries, each with capacity[i] (usable duration) and recharge[i] (time required to fully recharge).
You must follow the rules:
- 只能使用 fully-charged 電池
- 用完電池後立刻把它放回充電
- 如果需要用電池但是沒有任何 fully-charged → return -1
Return 你用了幾塊電池才夠時間 t;如果最後一塊沒用進去也必須所有電池都在充電狀態,否則 return -1。
核心邏輯
cur維護當前時間k[i]是電池下一次充滿的時間點- 能用的電池要滿足
k[i] <= cur - 用完後更新
k[i] = cur + recharge[i] - 不斷迭代直到
cur >= t
這題看似貪心,實際上就是模擬。難點是“最後一塊沒用進去”的判斷,很多人被這裡卡住。
Q4 — Primary + Secondary Arrays with Operations
這題在四道里最難,絕大多數人卡在這裡。
主題概觀
You’re given two arrays:primary and secondary, and a list of operations.
There are two types:
[0, index, val]→ update secondary[index] = val[1, targetSum]→ return count of pairs(i, j)such that
primary[i] + secondary[j] == targetSum
primary 不變,secondary 會頻繁 update。
為什麼遍歷會超時?
- 如果你每次遍歷 primary × secondary,就是 O(N*M) 完全爆炸
- 即使把 primary 做成 hashmap,然後遍歷 secondary 也是 O(N+M),每次 query 都太大
實際解法 Meta 給的 hint 很明顯:
“一種 array fixed / 一種 array dynamic”
→ 這是典型 two-sum with update 結構。
最佳解法:頻率表 + 動態維護
- 對 primary 建 freq(固定不變)
- 對 secondary 建 freq(可動態修改)
- type=0 時更新:從 freqSec 中刪舊值、加新值
- type=1 時查詢:
列舉 primary 的 distinct key,查targetSum - key在 secondary 中的頻率
→ O(P) 其中 P 是 primary 的 distinct 數量(通常遠小於 n)
這題跟 LeetCode 1 / 560 的那些 Two-Sum frequency 思路一致,但多了 dynamic update。
ProgramHelp:北美 CS 求職終極解決方案與高階服務矩陣
我們的團隊由來自 FAANG (Google, Meta, Amazon 等) 的前資深工程師以及 CMU、Stanford 等名校校友組成,我們提供的不是低端中介服務,而是行業頂級的、專家級的求職保障。
| 服務名稱 | 核心目標 | 適用平臺 |
| OA 輔助/代寫 | 確保所有測試用例 100% 透過 (All Cases Passed) | Codesignal, HackerRank, 牛客網, AMCAT 等 |
| 付款機制 | 不透過所有測試用例 不收費 | – |
| 操作安全 | 遠端控制實現無痕操作 | – |