Microsoft Interview Question for Software Engineer / Developers






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

A sorted link list contains a node as a structure of int and char *, As we read the next word, we will traverse the link list if we got the exact word then it increment the int of the node otherwise we will create a node in which we will allocate a memory of word length and add it at a proper place.
Link List : Best case : 1. Wrost case : n.
BST : Best case 1, Worst case n, Average Case : logn.

- shahidnitt August 29, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

A sorted link list contains a node as a structure of int and char *, As we read the next word, we will traverse the link list if we got the exact word then it increment the int of the node otherwise we will create a node in which we will allocate a memory of word length and add it at a proper place.
Link List : Best case : 1. Wrost case : n.
BST : Best case 1, Worst case n, Average Case : logn.

- shahidnitt August 29, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hash table could be a good solution with O(1) complexity. where key would be a no. and value reflects frequency.

- neo August 29, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Using a Trie will solve the purpose.
If the word is repeated, increase the repeat count at the leaf node. Otherwise add word in the list.
Time taken to increase repeat count will be (log n x d), where n is the length of longest word and d is the number of alphabets permitted(as per english dictionary which will be 26).
So Pseudo code can be formed as ..
1. Read the word getNextWord();
2. Look up the Trie table
2.a. If found incremnet the repeat count of the table else goto 2.b
2.b. Add the word in the Trie
3.Goto Step 1, Until all the words are read.

With English Dictionary the complexity will be O(log n)foe each word.

- aalok August 30, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@aalok: "With English Dictionary the complexity will be O(log n)foe each word."

Its not correct. The complexity will be linear in size of word length as with each character you traverse one none. So len(word) nodes at max.Thus complexity is O(len(word)).

- cool August 30, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@cool, yes as said by you the complexity of this algo will be 0(n) for each word.

- aalok August 31, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

i think we can use linked list for solving this problem efficiently
struct word
{
char str[20];
int count;
char flag;
};
initially flag is 'f' for all words in the document and count=0 for all whenever an word is discovered its flag is set to 't'
1.take word from document one by one using nextword()
2.if its flag is 'f' then count=1 else count=count+1;
3.keep untill we reach end of the document

- ramu kumar September 07, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

why not use a map<string, int>?

- b November 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

why not use a map<string, int>?

- b November 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You can use a map as well. The complexity is same as hash table

- Anonymous March 15, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

duh ! Why would you even consider a linked list when you can just use a hashtable? O(1) insert, lookup and O(n) space !

- Rahul Arakeri September 13, 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