Flag Repeat Photo Uploads Within a Short Upload Window

Last updated: November 29, 2026

Quick Overview

Given the sequence of content hashes for photos a user uploaded to Google Photos and an integer k, return True if the same hash appears twice at positions at most k apart.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given the sequence of content hashes for photos a user uploaded to Google Photos and an integer k, return True if the same hash appears twice at positions at most k apart.

A warm-up in the style of Google phone screens, tied to suppressing accidental double uploads in Google Photos backup. The interviewer checks whether you keep only the last-seen index per hash (or a size-k window set) rather than scanning back each time.

What the Interviewer Expects
  • Recognizes that only the most recent index of each hash matters
  • Uses a dictionary or bounded sliding set
  • Gets the boundary condition (distance <= k) right
  • Discusses memory when k is small versus large
  • Handles k = 0 and empty input
Key Topics to Cover
Hash Map
Sliding Window
Deduplication
Arrays
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Return all pairs of positions that are duplicates within k.
  • What if the condition is also that timestamps are within t seconds?
  • How would you bound memory to O(k) instead of O(distinct hashes)?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: hashes, a list of strings, and integer k >= 0.
  • Output: True if there exist i < j with hashes[i] == hashes[j] and j - i <= k.
  • k = 0 means no pair can qualify since indices must d...
High-Level Design

Scanning backward k positions for each element costs O(n * k). Instead keep last[h], the latest index where hash h appeared. When we see h at index j, the closest earlier copy is last[h], so...


Submit Your Answer
Markdown supported