Search⌘ K
AI Features

Problem: Find Duplicate File in System

Explore how to find groups of duplicate files in a file system by using hash tables to map file contents to their paths. Learn to parse directory information, implement efficient content-based grouping, and handle duplicates effectively using Java.

Statement

You are given a list paths, where each element is a string representing directory information. Each string contains a directory path followed by one or more files along with their contents in the following format:

"root/d1/d2/.../dm f1.txt(f1_content) f2.txt(f2_content) ... fn.txt(fn_content)"

This indicates that there are n files (f1.txt, f2.txt, …, fn.txt) with contents (f1_content, f2_content, …, fn_content) respectively, all located in the directory "root/d1/d2/.../dm". Here, n 1\geq 1 and m 0\geq 0. When m =0= 0, the directory is simply the root directory. A single blank space separates the directory path from each file entry.

Your task is to identify all groups of duplicate files in the file system. A group of duplicate files consists of at least 22 files that share the same content. For each such group, return the full file paths of all files with that identical content. A file path follows the format:

"directory_path/file_name.txt"

Return a list of all such groups. The answer may be returned in any order.

Note: You may assume that no files or directories share the same name within the same directory, and that each given directory info string represents a unique directory.

Constraints:

  • 1 ...