FastPrepRead-Optimized Duplicate Windows
Problem · Sliding Window

Read-Optimized Duplicate Windows

MediumGoogle logoGoogleFULLTIMEPHONE SCREEN
See Google hiring insights

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] 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.

The problem statement continues
Pro

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.

FastPrep Pro
Reported in 1 Google interview this week

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
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Google interview this week

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
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week