最近刚刷完 Confluent 的 OA,整体感觉比预期略难一点,属于那种看上去简单、但细节很多、边界容易出错的类型。整场测试共两道编程题,总时长 65 分钟,题目在 HackerRank 平台上完成。从题型来看,Confluent 这次的 OA 明显更偏逻辑类和数据结构应用类,不是算法陷阱题,而是看你代码思路是否清晰、能否正确处理边界条件。
Problem 1: Generate Two Binary Strings
Problem Description
Given an integer array nums, generate two binary strings string1 and string2 of the same length:
string1[i] = '1'ifnums[i]has appeared before (innums[0..i-1]), otherwise'0'.string2[i] = '1'ifnums[i]will appear again later (innums[i+1..n-1]), otherwise'0'.
Return [string1, string2].
Example
Input: nums = [1, 2, 1, 3]
Output: ["0010", "1000"]
Explanation:
string1 = "0010" because 1 appears again at index 2.
string2 = "1000" because only nums[0] (1) appears later again.
Approach
The most straightforward solution is to use sets to record which elements have already been seen:
- Traverse the array from left to right to build
string1:- Maintain a
seenset. - If
nums[i]is already inseen, append'1', otherwise'0'and add it to the set.
- Maintain a
- Traverse from right to left to build
string2:- Maintain another set
seen_from_right. - If
nums[i]appears again later (exists in the set), mark'1', else'0'and add it.
- Maintain another set
This approach takes O(n) time and O(n) space, very clean and efficient.
Key Notes
读题的时候要格外注意,“has appeared before” 和 “will appear again later” 是两个方向完全相反的判断。第一次读英文题容易混淆前后顺序,建议对照 example 理解一下,不然容易反过来写。
Problem 2: Duplicate Message Filter
Problem Description
A message delivery system needs to prevent duplicate messages from being sent within a short period of time.
If the same message has been successfully delivered within the last k seconds, then the new message should be considered a duplicate (False). Otherwise, it should be delivered (True) and update its last delivered timestamp.
You are given:
timestamps[i]: the arrival time of the i-th message (not necessarily sorted)messages[i]: the message textk: the time window in seconds
Return a boolean array indicating whether each message should be delivered (True) or dropped (False).
Example
Input:
timestamps = [1, 2, 4, 8, 10]
messages = ["a", "a", "a", "a", "a"]
k = 3
Output:
[True, False, True, True, False]
Explanation:
- At t=1, “a” is new → deliver.
- At t=2, “a” appeared 1s ago (<3) → drop.
- At t=4, difference = 3 → deliver (equal to k is allowed).
- At t=8, difference = 4 → deliver.
- At t=10, difference = 2 (<3) → drop.
Approach
Use a dictionary to record the last delivered timestamp of each message:
last_time = {}
res = []
for t, msg in zip(timestamps, messages):
if msg not in last_time or t - last_time[msg] >= k:
res.append(True)
last_time[msg] = t
else:
res.append(False)
This works for both sorted and unsorted timestamps as long as you process them in input order.
Key Pitfall
边界条件是这题最大的陷阱。
题中 “within the last k seconds” 意味着只要时间差小于 k 都算重复,等于 k 是允许发送的。
如果判断写成 > 而不是 >=,会直接导致半数测试不通过。
另外要注意输入可能不是升序的,如果乱序输入,就必须严格按输入顺序判断,而不能先排序,否则逻辑错误。
整体感受与策略
这份 OA 的整体难度属于 Leetcode 中等,第一题偏向逻辑构造,第二题偏工程实现。
两题都没有复杂算法,但都要求写出结构清晰、边界严谨的代码。
建议时间分配:
- 第一题 20 分钟左右足够,代码逻辑非常直接;
- 第二题 40 分钟较稳,尤其要留时间验证边界;
- 最后 5 分钟跑完所有测试、检查格式。
如果英文读题慢或者逻辑容易混淆,建议提前熟悉 HackerRank 的测试界面,例子读一遍后思考输入输出的含义。
顺利通关OA的秘诀
如果你最近也在准备 Bloomberg、Amazon、Citadel、Meta 等公司的 Online Assessment(OA),但又担心时间紧、题型陌生、怕挂在测试用例上,我们可以帮你。
Programhelp 专业提供 无痕 OA 辅助服务 —— 通过 ToDesk 远程联机,实时同步屏幕、语音提醒思路,全程安全不留痕迹。
适用于 HackerRank、CodeSignal、Codility、Karat 等常见平台,保证所有测试用例 100% 通过,不通过不收费。
想稳稳通过 OA、轻松拿下下一轮机会,可以私信了解详情,我们会根据岗位和公司定制方案。