Microsoft Interview Question for Software Engineer / Developers


Country: India
Interview Type: Written Test




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

we can use trie for it time and complexity in worst case would be O(m) where m = sum of number of letters in all words in the list....btw where u had written test for MS in banglore or hyderabad ?

- bnm March 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

if dictionary is implemented as the trie, this is the best solution. else if its an array of words, binary search

- srinivas April 01, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

we can use TST

- prity July 14, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

store dictionary in hash map. for the words check if key exists. complexity is linear

- yossee March 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Storing dictionary in a Hashmap may be difficult.
1. Because of the size of the dictionary
2. What hashing function to be used for anagrams which are also a part of the dictionary?

- Learner March 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Guess I didn't get the question quite right before. But I would like to point out that anagrams don't have the same hash code in the in-built hash maps.
If the dictionary is giving output in constant time, it just boils down to a simple iteration in linear time.

- yossee March 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

for each word in the given list , do the binary search in the dictionary .if present then print it else leave it .. time complexity O(klogn)

- jane March 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hii...can u share the interview details plz...

- ani March 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi .. can u share interview details.. was it for IDC?? and in which city??...plz share

- Mahesh March 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Complexity depends on the way the dictionary is available. So if the question needs complexity, we need to know this or make some assumptions.

- Anonymous March 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How would store whole dictionary???..

- Vineet Setia June 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can take it up as 2 steps process:
 Step 1 : Find all constituent words . (start, end). O(n^3 ) solution
 Step 2 :  Find a subset of constituent words (s1,e1), (s2,e2) ... (sn, en), such that 
                  s1 = 0, en = N and  si - e(i-1)  = 1
          Need help here.

Sample Code

Assume the dictionary is given as a Trie.
Assume words are all in lowercase, both in dictionary and as well as word.
Example word : hellboy == ( hell, boy) OR hellboy (assuming this to be a word)
constitutent words : (he,0,1) , (hell,0,3), (boy,4,6), (hellboy,0,6)
Aim : To find all constitutent words;
Approach :
   Start search gram wise 
   all 1-grams, all 2-grams, all 3-grams, all 4-grams, all 5-grams.
   DO A BFS 
   

Search Time :
1 gram : n   : 1 *n    = 1*n - 1 * 0
2 gram : n-1 : 2 (n-1) = 2n - 2 * 1
3 gram : n-2 : 3 (n-2) = 3n - 3 * 2 
4 gram : n-4 : 4 (n-3) = 4n - 4 * 3 
n gram : 1    :n  1    = n*n - n * (n -1 ) 
Total Complexity : n (1 + 2 + 3+ ... + n ) -  sum [ i (i-1)]  where i =0 .. n 
				= n * n (n+1)/ 2 -   (1^2 + 2^ 2 + 3^2 ... n^2 ) + ( 1+2 + 3 + ... +n )
				= O(n^3)

ListOfFoundWords :  (start, end, len)

Define a search				
SearchQueue : (start, end, len)
(0,1), (1,1), (2,1), (3,1), .. (n-1, 1)

Can I resume search in trie ? Nopes. Each search is going to be fresh . search a key of length k is O(k) operation in trie. But so is calculating Hash 

for ngramLength = 1;

for i  : 0 to word.length - 1;
  enqueue (i, ngramlength)

while( Queue not empty) 
    (start, len) = dequeue 
	 result = find (word, start, len ) in dictionary 
	 IF PATHFOUND  
		enqueue (start , len + 1)
	 ELSE IF WORDFOUND
		add to ListOfFoundWords
	 ELSE 
	     CONTINUE;

- Umesh June 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Step 2 : Can be done by Dijkstra's algorithm.

Treat (start, end ) as edges of a directed graph where start = vertex1, end = vertex2 .

Apply BFS to find a path between v1 and v2 .. where v1 = 0, v2 = N.

- Umesh June 10, 2012 | Flag


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