×

Instructions

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.


Package Tracking System - Hashing (Difficulty - Medium)


Package Tracking System – Detect Repeated Delivery Pattern

Problem Statement:

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.

Input:

  • package_log: A list of strings representing package IDs (1 ≤ length ≤ 10⁵)
  • k: An integer (1 ≤ k ≤ 1000)
  • Format: [PKG001, PKG002, ..., PKG999], k = X

Output:

Return the first repeated sequence of length k as a list. If no sequence is repeated, return an empty list.

[PKG001, PKG002, PKG003]

Constraints:

  • Package IDs are alphanumeric strings
  • Return the first sequence that is repeated
  • All comparisons are order-sensitive (consecutive sequences only)

Example 1:

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.
    

Example 2:

input: [A, B, C, D, E, F], k = 2
output: []

Explanation:
No sequence of 2 consecutive package IDs repeats.
    

Example 3:

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].
    

Example 4:

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.
    


Time Left:



Processing...

Error:


                

Output:

Test Case Result Input Correct Output Your Output




Submission Result