Microsoft Interview Question
Software Engineer / DevelopersTeam: Bing
Country: India
Interview Type: In-Person
perform a DFS and keep adding the directories in a hash table with their corresponding level number. For eg. root directory will have level number 0 and all sub-directories of root directory have level number 1 and so on.
Now if the directory pointed by soft link is present in hash table and the level number is less then the current level number, then it is pointing to one of it's ancestor
We need a HashTable<Directory>. Then traverse the tree in preOrder. For each directory d do. 1) push d in HT and if d is already exist then return false. 2) recursively do for each children node of d. 3)if all return true then remove d from HT and return true.
- Anonymous December 07, 2011