Read-Optimized Duplicate Windows
Problem statement
You are given an integer array nums and a fixed window length k. Maintain an index that answers whether any requested contiguous window of length k contains equal values at two different positions.
Process operations in order. Every row contains three integers:
[0, index, value]replacesnums[index]withvalue.[1, start, ignored]queries the window fromstartthroughstart + k - 1, inclusive. Append1if that window contains a duplicate value, or0otherwise. The third integer is ignored.
Return the query results in encounter order. Updates produce no output. Every query sees all preceding updates and no later ones. The array length and k never change.
Examples
Example 1
nums = [1,2,1,3]k = 3operations = [[1,0,0],[1,1,0],[0,2,2],[1,0,0],[1,1,0],[0,1,4],[1,0,0]]return = [1,0,1,1,0]Initially [1,2,1] contains a duplicate, but [2,1,3] does not. Replacing index 2 with 2 makes both windows contain duplicate twos. Replacing index 1 with 4 makes the first window [1,4,2], which is distinct.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 1 more worked example, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.