Please read the instructions carefully before starting the exam.
Once you start the exam, the timer will begin, and you cannot pause it.
Ensure that you complete and submit your code within the given time if the timer is enabled.
You work for a global logistics company that manages real-time delivery checkpoints. Each checkpoint logs incoming packages by their ID in sequence.
Due to system or routing issues, sometimes a pattern of consecutive packages gets repeated. Your job is to detect the first sequence of exactly k consecutive package IDs that appears more than once in the entire log.
The sequence must be repeated in the same order, and you should return the earliest such sequence that repeats.
[PKG001, PKG002, ..., PKG999], k = X
Return the first repeated sequence of length k
as a list. If no sequence is repeated, return an empty list.
[PKG001, PKG002, PKG003]
input: [PKG001, PKG002, PKG003, PKG004, PKG001, PKG002, PKG003], k = 3 output: [PKG001, PKG002, PKG003] Explanation: The sequence [PKG001, PKG002, PKG003] occurs at positions 0–2 and again at 4–6.
input: [A, B, C, D, E, F], k = 2 output: [] Explanation: No sequence of 2 consecutive package IDs repeats.
input: [X, Y, X, Y, X, Y], k = 2 output: [X, Y] Explanation: [X, Y] appears at index 0–1, 2–3, and 4–5. The first repeating sequence is [X, Y].
input: [P1, P2, P3, P4, P2, P3, P4, P5, P6], k = 3 output: [P2, P3, P4] Explanation: [P2, P3, P4] appears twice — first at index 1–3 and again at 4–6.