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:
- 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"[][]".
- Replace one
- 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"[]".
- Replace
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。