algoblazerEarly Access
LearnProblemsStudy GroupsMock InterviewTrail BlazeLeaderboard
Log inSign up

All problems

‹ Back to map
1 shown · 0/337 solved

First ID Repeated Within a Time Window

BronzeCommunity Beta
Asked atLenskart
Solve problem →
2000ms256MBAdded Oct 20, 2026

You are given a list of string ids ids and an integer array timestamps of the same length. Record i has id ids[i] and time timestamps[i]. timestamps is given in non-decreasing order.

For a record i, look at the most recent earlier record with the same id as record i, call it record j. Record i is a repeat within the window if timestamps[i] - timestamps[j] <= 10.

Return the id of the first record, by index, that is a repeat within the window. Return "NONE" if no record qualifies.

Examples

Example 1

Input: ids = ["tx1","tx2","tx1"], timestamps = [0,1,5]
Output: "tx1"
Explanation: The second "tx1" record, at index 2, has its most recent earlier "tx1" record at index 0. The gap is 5 - 0 = 5, which is at most 10.

Example 2

Input: ids = ["tx1","tx2","tx1"], timestamps = [0,1,15]
Output: "NONE"
Explanation: The second "tx1" record has a gap of 15 - 0 = 15 from its most recent earlier "tx1" record, which exceeds 10. No id repeats within the window.

Example 3

Input: ids = ["a"], timestamps = [0]
Output: "NONE"
Explanation: A single record has no earlier record to compare against.

Constraints

  • 1≤1 \leq1≤ ids.length === timestamps.length ≤105\leq 10^5≤105
  • 1≤1 \leq1≤ length of ids[i] ≤50\leq 50≤50, letters and digits only
  • 0≤0 \leq0≤ timestamps[i] ≤109\leq 10^9≤109
  • timestamps is sorted in non-decreasing order

Details

Solved by2 people
Time limit2000ms
Memory256MB
AddedOct 20, 20264 hours ago