Group Drive Files With Identical Content From Directory Listings
Last updated: November 29, 2026
Quick Overview
Given directory listings like 'root/a 1.txt(abcd) 2.txt(efgh)', where each file's content appears in parentheses, return groups of full file paths that have identical content, including only groups with two or more files.
0
0
0 solved
Given directory listings like 'root/a 1.txt(abcd) 2.txt(efgh)', where each file's content appears in parentheses, return groups of full file paths that have identical content, including only groups with two or more files.
This maps directly onto deduplication in Google Drive. The interviewer uses the parsing core to start, then spends real time on follow-ups: content too large to compare directly, hashing in chunks, and how to avoid false positives from hash collisions.
What the Interviewer Expects
- Parses directory and file entries correctly
- Maps content to a list of full paths
- Returns only groups with duplicates
- Discusses hashing large files and verifying byte equality
- Explains a size-first filter to avoid hashing everything
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
- Files are gigabytes; how do you find duplicates without reading every byte of every file?
- How do you avoid reporting false duplicates due to hash collisions?
- How would you run this across billions of Drive files?
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: list of strings, each
'<dir> <name>(<content>) ...'with one or more files. - Output: list of groups of paths
'<dir>/<name>'that share identical content, each group with at least two fil...
High-Level Design
For each listing, split on spaces: the first token is the directory, the rest are files. For each file token, find the '(' and split into name and content (stripping the trailing ')'). Append `dir + '...