TikTok OA Interview Coding Question: Nearby Duplicate Episode Check

14 Views
No Comments

Given an integer array v, where v[i] represents the episode watched on day i, and two integers k and t, determine whether there exist two different days i and j such that:

  • Day difference: abs(i - j) < k
  • Episode difference: abs(v[i] - v[j]) < t

Return True if both conditions are satisfied; otherwise, return False.

This problem asks whether there is a pair of indices whose distance is less than k and whose values differ by less than t. The standard solution uses a sliding window over the last k elements together with an ordered set or bucket-based lookup so each new value can be checked efficiently against nearby candidates. This avoids an O(n^2) brute-force scan and is a classic array + window + hashing/ordered-structure interview pattern.

END
 0