Remove Sub-Folders from the Filesystem | 2 Simple Approaches | Leetcode 1233 | codestorywithMIK
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 47th Video of our Playlist "Binary Tree : Popular Interview Problems" by codestorywithMIK
In this video we will try to solve a good string Problem : Remove Sub-Folders from the Filesystem | 2 Simple Approaches | Leetcode 1233 | codestorywithMIK
I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.
Problem Name : Remove Sub-Folders from the Filesystem | 2 Simple Approaches | Leetcode 1233 | codestorywithMIK
Company Tags : will update later
My solutions on Github(C++ & JAVA) - https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/strings/Remove Sub-Folders from the Filesystem.cpp
Leetcode Link : https://leetcode.com/problems/remove-sub-folders-from-the-filesystem
My DP Concepts Playlist : • Roadmap for DP | How to Start DP ? | ...
My Graph Concepts Playlist : • Graph Concepts & Qns - 1 : Graph will...
My Recursion Concepts Playlist : • Introduction | Recursion Concepts And...
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK
Subscribe to my channel : / @codestorywithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Summary :
Approach 1: Set-Based Subfolder Removal
Idea: This approach uses a Set to track all folders. For each folder, it checks if any of its parent directories exist in the set. If a parent directory exists, the current folder is considered a sub-folder and is excluded from the result.
Key Steps:
Store all folders in a Set.
For each folder, iteratively check if any parent directory is in the set.
If no parent is found, the folder is added to the result list.
Time Complexity: O(n * l), where n is the number of folders and l is the length of the folder path (for string manipulation).
Approach 2: Sorting-Based Subfolder Removal
Idea: This approach sorts the folders lexicographically, ensuring that sub-folders come right after their parent directories. It then checks each folder to see if it starts with the last added folder (plus a / to differentiate between folders and sub-folders).
Key Steps:
Sort the folders lexicographically.
Compare each folder with the last added folder to see if it is a sub-folder (using startsWith()).
Only add folders to the result list if they are not sub-folders.
Time Complexity: O(n * log(n) + n * l), where n is the number of folders (due to sorting) and l is the folder path length.
Both approaches efficiently identify and remove sub-folders, with one using sorting and the other using a set-based parent-check mechanism.
✨ Timelines✨
00:00 - Introduction
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #coding #programming #100daysofcode #developers #techjobs #datastructures #algorithms #webdevelopment #softwareengineering #computerscience #pythoncoding #codinglife #coderlife #javascript #datascience #leetcode #leetcodesolutions #leetcodedailychallenge #codinginterview #interviewprep #technicalinterview #interviewtips #interviewquestions #codingchallenges #interviewready #dsa #hindi #india #hindicoding #hindiprogramming #hindiexplanation #hindidevelopers #hinditech #hindilearning #helpajobseeker #jobseekers #jobsearchtips #careergoals #careerdevelopment #jobhunt #jobinterview #github #designthinking #learningtogether #growthmindset #digitalcontent #techcontent #socialmediagrowth #contentcreation #instagramreels #videomarketing #codestorywithmik #codestorywithmick #codestorywithmikc #codestorywitmik #codestorywthmik #codstorywithmik #codestorywihmik #codestorywithmiik #codeistorywithmik #codestorywithmk #codestorywitmick #codestorymik #codestorwithmik