Two Sigma 面試 分享|Two Sigma OA |75 分鐘兩題 2025 最新題目復盤

10.12 剛做完 Two Sigma 面試,這次 OA 依舊在 HackerRank 平臺,總時長 75 分鐘,兩道題。
整體感覺題目品質挺高的,但節奏比較緊湊。 第一題邏輯判斷強一點,第二題雖然看著篇幅很長,但其實只是計算+字串處理,屬於典型的“紙老虎”題。

Two Sigma 面試 基本資訊

日期:2025.10.12

時長:75 分鐘

題目數量:2 題

難度:中等偏下

平臺:HackerRank

助攻模式:Programhelp 無痕連線 + 語音節奏提醒

Question 1

Balanced Split String with Wildcards

Determine the number of ways a string containing the characters '(', ')', '[', ']', and '?' can be divided into two non-empty substrings such that each substring can be rearranged to form a balanced string.

The '?' characters can be replaced with any bracket character ('(', ')', '[', or ']') as needed to achieve balance.
The two substrings together must cover the entire original string and cannot overlap.

A balanced string is one where all brackets are properly matched and nested.
For example:

"([])", "()[]", and "[[]]" are balanced.

"([)]", "(()", and "][" are not.

A substring is a contiguous block of the original string.

Example

Let
s=′[?(]??[?′s = ‘[?(]??[?’s=′[?(]??[?′

We can split it in the following two valid ways:

  1. s1=’[?(]’s_1 = \text{‘[?(]’}s1​=’[?(]’, s2=’??[?’s_2 = \text{‘??[?’}s2​=’??[?’
    • Replace one '?' in s1s_1s1​ with ) to make it rearrangeable to a balanced "()[]".
    • Replace the '?'s in s2s_2s2​ with [] so it can be rearranged into "[][]".
  2. s1=’[?(]??’s_1 = \text{‘[?(]??’}s1​=’[?(]??’, s2=’[?’s_2 = \text{‘[?’}s2​=’[?’
    • Replace '?'s in s1s_1s1​ to make it "()[][]".
    • Replace '?' in s2s_2s2​ with ] to make "[]".

Thus, the total number of valid splits is 2.

Constraints

  • 4≤length of s≤1054 \leq \text{length of } s \leq 10^54≤length of s≤105
  • sss contains only '(', ')', '[', ']', and '?'

Question 2

Closest Pure Color

A color is represented as a 24-bit integer, with 8 bits each for red (R), green (G), and blue (B) components.
Each component ranges from 0 (low intensity) to 255 (high intensity).

The distance between two colors with RGB values (r1,g1,b1)(r_1, g_1, b_1)(r1​,g1​,b1​) and (r2,g2,b2)(r_2, g_2, b_2)(r2​,g2​,b2​) is given by: d=(r1−r2)2+(g1−g2)2+(b1−b2)2d = \sqrt{(r_1 – r_2)^2 + (g_1 – g_2)^2 + (b_1 – b_2)^2}d=(r1​−r2​)2+(g1​−g2​)2+(b1​−b2​)2​

We compare a given pixel’s color to these five pure colors:

Pure Color R G B
Black 0 0 0
White 255 255 255
Red 255 0 0
Green 0 255 0
Blue 0 0 255

Given a 24-bit binary string representing a pixel’s RGB value, determine which pure color it is closest to.
If the pixel is equally close to multiple colors, output "Ambiguous".

Example

Input

n = 1
pixels = ["000000001111111100111100"]

Step 1: Parse the binary string

Split into 3 components (8 bits each):

  • R = "00000000" → 0
  • G = "11111111" → 255
  • B = "00111100" → 60

Thus, the pixel’s RGB = (0, 255, 60).

Step 2: Compute distance to each pure color

Step 3: Find the closest

The smallest distance is to Green (d = 60),
so the result is "Green".

Function Description

Complete the function closestColor with the following parameter(s):

def closestColor(pixels: List[str]) -> List[str]:

Parameters

  • pixels[n]: an array of 24-bit binary strings representing pixels

Returns

  • List[str]: for each pixel, return the name of the closest pure color, or

整體感受

這場 OA 的體驗非常流暢,沒有花哨的陷阱。

  • 第一題考邏輯,第二題考實現。
  • 都是可通過分析拆解的中檔題。

Programhelp 助攻的節奏提醒在時間管理上説明很大:

“第一題 45 分鐘打底,第二題別慌,一定留 25 分鐘做測試。”

正是這種節奏規劃,讓很多同學能穩定在最後幾分鐘通過所有 hidden cases。

最後總結

Two Sigma 的 OA 不難,但非常講究思路清晰和實現穩定。
尤其第一題這種“平衡類”問題,很多人容易寫複雜棧邏輯,反而浪費時間。
如果能提前通過 mock 或助攻訓練熟悉題型節奏,上場時自然更穩。

Programhelp 面試助攻團隊為你的 Offer 保駕護航

我們為 Two Sigma、Jane Street、Citadel、IMC、Amazon 等眾多公司面試提供:

無痕聯機 OA 輔助(HackerRank / CodeSignal / Codility)

語音即時提示,思路卡點立刻提醒

模擬面試演練 + 思維框架梳理

説明你在最短時間內拿下高薪 offer。

author avatar
jor jor
END
 0