Read-Optimized Duplicate Windows
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The whole problem hinges on one precomputed array, and Google's September 2026 OA wants you to see it fast. You're maintaining a boolean flag per window start, so every query is a single array lookup. Updates are where the work lives. If you're sitting on an invite for this week, the trick is deciding what to store and when to rebuild it. Most people try to be clever with incremental counts and burn their time. If you blank on the structure during the live OA, StealthCoder is the safety net running invisibly on your screen, but the idea is simple enough to hold in your head.
The problem
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] replaces nums[index] with value. [1, start, ignored] queries the window from start through start + k - 1, inclusive. Append 1 if that window contains a duplicate value, or 0 otherwise. 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. Optimize for a read-heavy workload: target O(1) work per query, O(n) work per update, and O(n) index space, where n = nums.length. Hash-table counting gives expected linear update time. Output storage is separate from index space. Function duplicateWindowQueries(nums: int[], k: int, operations: int[][]) → int[] Examples Example 1 nums = [1,2,1,3] k = 3 operations = [[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. Example 2 nums = [4,5,6] k = 3 operations = [[1,0,9],[0,2,4],[1,0,-8],[0,0,9],[1,0,7]] return = [0,1,0] There is one full-array window. Its values change from [4,5,6] to [4,5,4] and then [9,5,4]. The third field of each query has no effect. Constraints 1 <= nums.length <= 1000 1 <= k <= nums.length 0 <= operations.length <= 300, and each row has exactly three integers. Initial and replacement values are between -1000000 and 1000000. Update indices satisfy 0 <= index < n; query starts satisfy 0 <= start <= n-k. The ignored query field is any integer between -1000000 and 1000000.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Store a result array dup[s] for every valid window start s, which is n-k+1 entries. A query returns dup[start] in O(1). On each update, set nums[index] and recompute. The simple route: rebuild all window flags in O(n) using a sliding window with a hash map of counts and a running count of values with frequency above 1. Slide from start 0 to n-k, adding the right element and removing the left one, and record whether the duplicate counter is positive. That's O(n) time and O(n) space for dup plus the map. The pitfall is recomputing each window from scratch, which is O(n*k) per update and misses the target. Another trap is decrementing a count to 1 and forgetting to lower the duplicate counter. Remember the third field is ignored on queries, and updates append nothing. With 300 operations and n up to 1000, the rebuild approach is comfortably fast. If the live OA freezes your head, StealthCoder can hand you this structure as a hedge.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Read-Optimized Duplicate Windows cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Read-Optimized Duplicate Windows FAQ
What's the trick in Read-Optimized Duplicate Windows?+
Precompute a flag array with one entry per window start. Queries become O(1) lookups. Each update rewrites the value and rebuilds all flags with a sliding window plus a hash map of counts. That matches the O(n) update and O(n) space targets in the prompt.
How do I rebuild the flags in O(n)?+
Slide a window across the array while keeping a count map and a counter of values whose frequency is at least 2. When a count goes from 1 to 2, increment the counter. When it drops from 2 to 1, decrement it. Flag is 1 when the counter is positive.
Why not recompute only the affected windows on update?+
You can. Only windows containing the changed index can flip, up to k of them. But rechecking each from scratch costs O(k) apiece, so O(k^2) overall. A full sliding rebuild is simpler, safe, and meets the O(n) bound with fewer bugs.
What edge cases show up in this Google question?+
k equal to n gives a single window. Updates that write the same value change nothing but still work with a rebuild. Negative values and large magnitudes are fine for a hash map. The third query field is arbitrary, so never read it.
How should I prepare in 48 hours?+
Write the sliding window with a frequency map and a duplicate counter from memory twice. Then write the wrapper that handles operations, mutating nums on type 0 and appending dup[start] on type 1. Test it against both examples, including the one with a single window.