609. Find Duplicate File in System

 609Find Duplicate File in System

Given a list paths of directory info, including the directory path, and all the files with contents in this directory, return all the duplicate files in the file system in terms of their paths. You may return the answer in any order.

A group of duplicate files consists of at least two files that have the same content.

A single directory info string in the input list has the following format:

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

It means there are n files (f1.txt, f2.txt ... fn.txt) with content (f1_content, f2_content ... fn_content) respectively in the directory "root/d1/d2/.../dm". Note that n >= 1 and m >= 0. If m = 0, it means the directory is just the root directory.

The output is a list of groups of duplicate file paths. For each group, it contains all the file paths of the files that have the same content. A file path is a string that has the following format:

  • "directory_path/file_name.txt"

 

Example 1:

Input: paths = ["root/a 1.txt(abcd) 2.txt(efgh)","root/c 3.txt(abcd)","root/c/d 4.txt(efgh)","root 4.txt(efgh)"]
Output: [["root/a/2.txt","root/c/d/4.txt","root/4.txt"],["root/a/1.txt","root/c/3.txt"]]

Example 2:

Input: paths = ["root/a 1.txt(abcd) 2.txt(efgh)","root/c 3.txt(abcd)","root/c/d 4.txt(efgh)"]
Output: [["root/a/2.txt","root/c/d/4.txt"],["root/a/1.txt","root/c/3.txt"]]

 

Constraints:

  • 1 <= paths.length <= 2 * 104
  • 1 <= paths[i].length <= 3000
  • 1 <= sum(paths[i].length) <= 5 * 105
  • paths[i] consist of English letters, digits, '/''.''('')', and ' '.
  • You may assume no files or directories share the same name in the same directory.
  • You may assume each given directory info represents a unique directory. A single blank space separates the directory path and file info.

 Solution:

Well, looking at the question it seems straightforward forward and it is straight forward. You just need to apply the things coming to your mind. Give it a try by your self and if you are stuck then you can see the solution code below.

Post a Comment

1 Comments


  1. -- CREATE TABLE STUDENT_TABLE ( SNO INT , ROLLNO INT, ENROLL INT , STUDENT_NAME varchar(50), COURSEID INT , EMAILID VARCHAR(50) , MOBILE varchar(10));
    -- INSERT INTO STUDENT_TABLE VALUES (1 , 20115001 , 200561, "AADI REDHU" , 101 , "aadi@email.com" , "998587654");
    -- INSERT INTO STUDENT_TABLE VALUES (2 , 20115002 , 200461, "AAYUSH" , 104 , "ayush@email.com" , "998581654");
    -- INSERT INTO STUDENT_TABLE VALUES (3 , 20115003 , 200581, "ABHINAV" , 109 , "abhinav@email.com" , "978587654");
    -- INSERT INTO STUDENT_TABLE VALUES (4 , 20115004 , 200961, "ajay" , 107 , "ajay@email.com" , "998587154");
    -- INSERT INTO STUDENT_TABLE VALUES (5 , 20115005 , 200361, "raunit" , 102 , "raunit@email.com" , "998537654");

    -- (i) ALTER TABLE STUDENT_TABLE ADD PRIMARY KEY(ENROLL);

    -- (ii) SELECT LEFT(STUDENT_NAME, 2 ) FROM STUDENT_TABLE;

    -- ALTER TABLE STUDENT_TABLE ADD SEMESTER INT;
    -- CREATE TABLE COURSE_TABLE ( COURSEID INT , COURSE_NAME varchar(50), DURATION INT );
    -- INSERT INTO COURSE_TABLE VALUES (101 , "OS" , 10);
    -- INSERT INTO COURSE_TABLE VALUES (102 , "DBMS" , 17);
    -- INSERT INTO COURSE_TABLE VALUES (104 , "CN" , 19 );
    -- INSERT INTO COURSE_TABLE VALUES (109 , "DSA" ,14);
    -- INSERT INTO COURSE_TABLE VALUES (107 , "ACA" , 12 );
    -- (iii )SELECT STUDENT_TABLE.ROLLNO, STUDENT_TABLE.STUDENT_NAME, STUDENT_TABLE.SEMESTER, COURSE_TABLE.COURSE_NAME from STUDENT_TABLE RIGHT JOIN COURSE_TABLE ON STUDENT_TABLE.COURSEID= COURSE_TABLE.COURSEID;

    -- (IV) select substring_index(EMAILID, '@' , 1) AS FIRSTNAME, substring_index(EMAILID, '@' , -1) AS DOMAIN FROM STUDENT_TABLE;

    ReplyDelete

If you have any doubts/suggestion/any query or want to improve this article, you can comment down below and let me know. Will reply to you soon.