You have a list of Unix file paths present in the system without repetition. Then there is another list of file paths which are required to be created based on the previous list.
The Unix file path is tree based. :) So, it obviously gives as the idea that, we need to do a tree.
The problem statement is here: http://code.google.com/codejam/contest/dashboard?c=635101#
You will be given a list of directory already present in the system like this,
and you will be asked to create the following new directories
We should basically check whether directory is already present in the system and also check how many new directories are required.
The output of the above code will be: 2
Since only tom & jerry directories need to be created newly.
- When reading the first input of currently present directories, just create a tree (with multiple children). Make sure that you make the next child dir in the path as a children to the previous parent dir path
- After you read path given as present in the system into a tree, next is to read the list of paths for which presence need to verified + new directory need to be created.
- Even in this case do the same first step. Just start creating the tree and ignore if directory already present. If not present, Just get the count of it which is not already present in the tree.
- Also after taking the count, again add the new dir to the actual tree.
- You are done with the solution!! :)