Confluent 最新 OA 複盤|兩題中等偏上強度,全程監控+ 邊界坑點詳解

最近剛刷完 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' if nums[i] has appeared before (in nums[0..i-1]), otherwise '0'.
  • string2[i] = '1' if nums[i] will appear again later (in nums[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 seen set.
    • If nums[i] is already in seen, append '1', otherwise '0' and add it to the set.
  • 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.

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 text
  • k: 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、輕鬆拿下下一輪機會,私訊了解詳情,我們會根據職位和公司量身訂做方案。

author avatar
jor jor
END
 0