Amazon Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: In-Person
think of it as cutting a tree at a particular node. you end up removing entire subtree rooted at that node. so i guess the one mentioned by book is correct and efficient approach
So if I just remove a directory by simply removing it from its parent's sub-directories list, that would automatically remove all if its sub-directories and sub files too? Don't they still exist in heap?
According to Cracking the code interview, the solution doesn't recursively delete the sub-directories and files, it just calls parent.remove(entry), which will remove the given entry from its parent's list. Is this the right way to do it? I thought we are supposed to delete all of its sub-directories and files before we go to its parent and move it from the list.
- Guy January 29, 2014