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.
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample Answer
Requirements
- Input:
hashes, a list of strings, and integerk >= 0. - Output: True if there exist
i < jwithhashes[i] == hashes[j]andj - 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...