Abnormal Security logoAbnormal Security
Coding·60 minFree preview

Find Duplicate Images in a Directory

The 60-minute phone screen is the same custom problem for every SWE candidate. It starts with ~20 minutes of discussion on how to detect duplicate images, then ~30-40 minutes of coding: walk a directory (`os.walk`), call the provided `_calculate_hash` helper on each file, and output every group of duplicates. Follow-ups cover hash collisions, limited memory, near-duplicate (transformed) images, and productionizing at scale with Redis and map-reduce.

SWE
deduplication
hashing
filesystem
memory-bounded
scaling
Frequency
Medium
Last asked
2025-07-15
Stage
phone-screen

Problem

This is a custom problem, not a LeetCode one. Per the recruiter, every phone screen uses this same question. The 60-minute session has two parts:

  1. Discussion (~20 min): "How do you identify duplicate images?" Clarify what counts as a duplicate first. In the 2025 version the interviewer wanted exact same file duplicates only, with no ML / computer vision needed.
  2. Coding (~30-40 min): You get a list or directory of image files and write a function (the "main function") that outputs all images that are duplicates.
    • The files sit in a directory, so you read them from disk by walking it with os.walk. The interviewer may hint at how os.walk works.
    • A helper _calculate_hash is provided. Call it directly instead of writing your own hashing.
    • In one version the "images" are files containing ASCII art.

Variants

Near-duplicate discussion

In the 2024 version, the discussion went past exact copies:

  • How do you identify images that are transformed: rotated, translated, or with changed brightness?
  • How do you identify similar images? The expected direction is an ML model.

Pitfalls

  • The coding prompt changes slightly from the problem you just discussed. Re-read it before coding, or you may solve the wrong problem.
  • Settle the definition of "duplicate" (byte-identical vs. visually similar) before going deep. It decides whether ML belongs in the answer at all.
  • One candidate found the interviewers unreceptive to a stream of questions. Keep clarifications focused and few.

Follow-ups

Preparation

  • Write a find_duplicates(root) that walks a directory with os.walk, hashes each file through a given helper, and returns groups of duplicate paths. Aim for under 20 minutes.
  • Extend it with a size-first pass and chunked hashing, then add a byte-compare check on each hash group.
  • Get comfortable with os.walk's (dirpath, dirnames, filenames) tuples and os.path.join, so the file-reading part costs no time.
  • Prepare a 1-2 minute spoken answer to each follow-up above: collisions, limited memory, Redis / map-reduce scale-out, cloud app integration, transformed images.
Was this article helpful?

Comments

Sign in to join the discussion
Loading...