Goldman Sachs 2026 SDE Intern OA 面经分享|HackerRank 两种题型模式解析 + 高频题复盘

35Times read
No Comments

最近刚结束 Goldman Sachs 2026 SDE Intern OA 。整体体验下来,今年 OA 的结构其实比较清晰,难度也没有想象中那么离谱,不过确实有不少细节坑。如果平时刷题不太注意边界条件,很容易在看似简单的题上翻车。趁着记忆还比较清楚,整理一下这次 OA 的整体流程和遇到的题型,给后面准备的同学做个参考。

Goldman Sachs 2026 SDE Intern OA 面经分享|HackerRank 两种题型模式解析 + 高频题复盘

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.

Constraints
1 <= prices.length <= 10^5
0 <= prices[i] <= 10^4

解题思路

这是一道非常经典的股票买卖问题,本质是在考察贪心算法的应用。核心思路是遍历数组的同时维护当前为止的最低买入价格,并尝试用当前价格作为卖出价计算最大利润。

整个过程中需要维护两个状态变量,一个是当前最低价格 min_price,另一个是当前最大利润 max_profit。当遍历到新的价格时,先更新最低价格,再计算当前卖出的利润,并更新最大利润。

时间复杂度是 O(n),因为只需要遍历一次数组。
空间复杂度是 O(1),只使用了常数级额外变量。

代码实现

def maxProfit(prices):
    if not prices or len(prices) < 2:
        return 0

    min_price = prices[0]
    max_profit = 0

    for price in prices[1:]:
        min_price = min(min_price, price)
        max_profit = max(max_profit, price - min_price)

    return max_profit


# Test cases
test_cases = [
    [7, 1, 5, 3, 6, 4],
    [7, 6, 4, 3, 1],
    [1, 2, 3, 4, 5],
    [5, 4, 3, 2, 1]
]

for i, prices in enumerate(test_cases):
    result = maxProfit(prices)
    print(f"Test case {i+1}: {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:

  1. Open brackets must be closed by the same type of brackets
  2. Open brackets must be closed in the correct order
  3. 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

Constraints
1 <= s.length <= 10^4
s 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实时助攻 ,帮助快速定位解题方向。

author avatar
Jory Wang Amazon资深软件开发工程师
Amazon 资深工程师,专注 基础设施核心系统研发,在系统可扩展性、可靠性及成本优化方面具备丰富实战经验。 目前聚焦 FAANG SDE 面试辅导,一年内助力 30+ 位候选人成功斩获 L5 / L6 Offer。
End of text
 0