最近剛結束 Goldman Sachs 2026 SDE Intern OA 。整體體驗下來,今年 OA 的結構其實比較清晰,難度也沒有想象中那麼離譜,不過確實有不少細節坑。如果平時刷題不太注意邊界條件,很容易在看似簡單的題上翻車。趁著記憶還比較清楚,整理一下這次 OA 的整體流程和遇到的題型,給後面準備的同學做個參考。

OA 平臺與題型結構
今年 Goldman Sachs 的筆試基本都在 HackerRank 平臺進行。系統會根據申請時填寫的資訊分配 A / B 兩套題,而不是隨機抽題,所以不同人遇到的題型結構可能不完全一樣。
整體主要有兩種模式。一種是 120 分鐘的純 Coding 模式,一般是三到四道演算法題,難度大致在 LeetCode Medium。另一種是 180 分鐘的混合模式,包含兩道 Coding 題和九道數學題。
Goldman Sachs 2026 SDE Intern OA 真題回顧
Problem 1: Stock Price Analysis (Medium)
題目說明
You are given an array of stock prices where prices[i] represents the price of a stock on day i. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.
Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.
Example 1
Input: prices = [7,1,5,3,6,4]
Output: 5
Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6 – 1 = 5.
Example 2
Input: prices = [7,6,4,3,1]
Output: 0
Explanation: In this case, no transactions are done and the max profit = 0.
Constraints1 <= prices.length <= 10^50 <= prices[i] <= 10^4
解題思路
這是一道非常經典的股票買賣問題,本質是在考察貪心演算法的應用。核心思路是遍歷陣列的同時維護當前為止的最低買入價格,並嘗試用當前價格作為賣出價計算最大利潤。
整個過程中需要維護兩個狀態變數,一個是當前最低價格 min_price,另一個是當前最大利潤 max_profit。當遍歷到新的價格時,先更新最低價格,再計算當前賣出的利潤,並更新最大利潤。
時間複雜度是 O(n),因為只需要遍歷一次陣列。
空間複雜度是 O(1),只使用了常數級額外變數。
程式碼實現
def maxProfit(prices):
if not prices or len(prices) {result}")
Problem 2: Valid Parentheses with Multiple Types (Medium)
題目說明
Given a string s containing just the characters ( ) { } [ and ], determine if the input string is valid.
An input string is valid if:
- Open brackets must be closed by the same type of brackets
- Open brackets must be closed in the correct order
- Every close bracket has a corresponding open bracket of the same type
Example 1
Input: s = "()"
Output: true
Example 2
Input: s = "()[]{}"
Output: true
Example 3
Input: s = "(]"
Output: false
Constraints1 <= s.length <= 10^4s consists of parentheses only '()[]{}'.
解題思路
這是一道典型的棧結構應用題,用於檢測字串中的括號是否匹配。核心思路是使用棧來儲存遇到的左括號,當遇到右括號時檢查棧頂元素是否與之匹配。
如果匹配則彈出棧頂元素,如果不匹配或者棧為空則說明字串無效。遍歷結束後,如果棧為空說明所有括號都成功匹配。
時間複雜度是 O(n),因為只需要遍歷字串一次。
空間複雜度是 O(n),最壞情況下棧需要儲存所有字元。
程式碼實現
def isValid(s):
stack = []
mapping = {
')': '(',
']': '[',
'}': '{'
}
for char in s:
if char in mapping:
if not stack or stack[-1] != mapping[char]:
return False
stack.pop()
else:
stack.append(char)
return len(stack) == 0
瞭解更多
如果你馬上要參加 OA,但對刷題範圍、題型結構還不太確定,其實提前瞭解真實題型會非常有幫助。很多同學在筆試裡卡住,並不是不會寫程式碼,而是沒有見過類似的題型,思路一時間打不開。
我們這邊長期整理各大廠最新 OA 真題,包括 Amazon、Goldman Sachs、TikTok、Citadel、JPMorgan 等公司的筆試題庫,題型更新比較及時。如果在考試過程中遇到卡題或者時間不夠的情況,也可以提供 OA實時助攻 ,幫助快速定位解題方向。