Problem · Hash Table

Notification Deduplication Window

Learn this problem
MediumGoldman Sachs logoGoldman SachsFULLTIMEONSITE INTERVIEW

Problem statement

A notification service receives a finite batch of arrivals. The arrays notificationIds and timestamps describe the same n arrivals in order. Each timestamp is measured in seconds, and the timestamps are nondecreasing.

Process each arrival using a 600-second deduplication window:

  • An arrival is a duplicate when the same notification ID was seen less than 600 seconds earlier.
  • An arrival exactly 600 seconds after the previous sighting is not a duplicate.
  • Every arrival becomes the new last sighting for its ID, including an arrival that is suppressed as a duplicate.

Return a boolean array in arrival order. Return true for an accepted notification and false for a suppressed duplicate.

Memory requirement

Discard identifiers as soon as their most recent sighting leaves the active window. The retained state must remain proportional to the identifiers still active in the window rather than the total number of processed arrivals.

Function

deduplicateNotifications(notificationIds: String[], timestamps: int[]) → boolean[]

Examples

Example 1

notificationIds = ["A","B","A","A"]timestamps = [0,100,599,1199]return = [true,true,false,true]

The arrival of A at 599 is suppressed because it is 599 seconds after the first A. That duplicate refreshes the last-seen time to 599. The final A arrives exactly 600 seconds later, so it is accepted.

Example 2

notificationIds = ["X","X","Y","X","Y"]timestamps = [42,42,42,641,642]return = [true,false,true,false,true]

The second X is a duplicate at the same timestamp. The X at 641 is still inside its window, while the Y at 642 is exactly 600 seconds after its previous sighting and is accepted.

Example 3

notificationIds = ["N","N","N","N"]timestamps = [10,609,1208,1808]return = [true,false,false,true]

Each suppressed arrival refreshes N, so the arrivals at 609 and 1208 remain duplicates. The final arrival is exactly 600 seconds after the refreshed time 1208 and is accepted.

Constraints

  • 1 <= n <= 2 * 10^5
  • notificationIds.length == timestamps.length == n
  • Each value in notificationIds is a non-empty opaque identifier string.
  • 0 <= timestamps[i] <= 10^9
  • timestamps[i] <= timestamps[i + 1] for every valid i.
  • Timestamps are measured in whole seconds.

More Goldman Sachs problems

drafts saved locally
public boolean[] deduplicateNotifications(String[] notificationIds, int[] timestamps) {
    // Write your code here
}
notificationIds["A","B","A","A"]
timestamps[0,100,599,1199]
expected[true,true,false,true]
checking account