Microsoft Interview Question for Software Engineer / Developers


Team: Bing
Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
1
of 1 vote

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.

public boolean check(Directory d){
   if(HT.get(d))
       return false;
   else{
     for(int i=0;i<d.subdir.length;i++){
         if(check(d.subdir[i]) == false)
            return false;
     }//endfor
     HT.remove(d);
     return true;
   }
}

- Anonymous December 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

I guess there is some sort of symbolic link from child to an ancestor,
or else I don't know how we can make a child subdir point to an ancestor dir.

If thats the understanding, then the prob boils down to, given a directed graph,
find a back edge upon dfs (basically detecting a cycle).

- kartikaditya December 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

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

- Anonymous December 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

May be just a DFS traversal will do, given the structure is stored as graphs

- Anonymous December 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Create a BST or a sorted list of addresses only. If there's a clash, you've the directory that links to one of the parents.

- shanuapril December 11, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

DFS travel a graph. using colors to indicate the traversal status.

- hoganxian January 02, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More