LeetCode - 609. Find Duplicate File in System | Day 18 May Challenge
Aditya Mahajan
Problem: https://leetcode.com/problems/find-duplicate-file-in-system/ Code Link: https://github.com/skystone1000/Coding-Problems/tree/master/Leet%20Code/May%20Challenge%202021
May Challenge 2021 - Day 18
- Find Duplicate File in System
So the basic steps that we need to do while solving this problem are 1) Generate the paths of all directories 2) Link the data in files with the path 3) Compare with other files to see if we have duplicates
Approach 1 - Brute Force (TLE) In the brute force approach, we first try to generate all the paths and file contents in a vector of pair and then with two nested for loops we can check for each element in the vector and see if its duplicate exists (along with maintaining a visited vector so that we do not do unnecessary work) and then append them finally to our answer. But this is not an optimal approach.
Approach 2 - HashMap So we can optimize the searching time that we have in two nested for loops by using a different data structure. As we need to access the elements multiple times and we need fast lookup so we can use a hashmap and also ordering is not required so unordered map can do the work. So while generating the paths and contents we push them to the groups with similar content.
TIMESTAMPS 0:00 Intro 0:19 Question 1:08 Examples 2:32 Approach 1 - Brute force 4:06 Approach 2 - HashMap 5:39 Code 8:07 Output
š Social Media š š LinkedIn: https://www.linkedin.com/in/adityamahajan123/ š GitHub: https://github.com/skystone1000/ šø Instagram: https://www.instagram.com/skystone1000/ š Chess.com : https://www.chess.com/member/skystone1000 ā Discord Server: https://discord.gg/ZPWzT5QWDC
ā” Please leave a LIKE and SUBSCRIBE for more content! ā”
ā Tags ā
- Aditya Mahajan
ā Hashtags ā #leetcode #609Leetcode ... https://www.youtube.com/watch?v=7j9pDf02B80
50928428 Bytes