Microsoft Interview Question for Software Engineer / Developers


Country: United States




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

Trie is the simple solution for the simple developers ;)

The small challenge comes when pressing 'J' to search should show you names like "John May" and "May, John" as well (two Tries can solve it somehow).

A bigger one comes when the 'J' can be anywere in the name. Trie is out of scope in this case (as far as I see).

And the real one comes when it is a phonebook with Chinese names (oh, yeah, the World is not ASCII, it is Unicode!) and you have to search for "li" (read: show names where the pronounciation of the stored Chinese/Unicode character starts as "li")

Another interpretation can be that the key sequence should match the letter that are on the key - e.g. '2' should be OK for 'a' or 'b' or 'c' and so on. So '25' should match "Al". The word "telephone keypresses" suggest this kind of interpretation.

Oh, and another issue to handle with Tries is the letters that are treated as equals when matching - like n and ñ, but they are different in the real names.

- Selmeczy, Péter January 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

This is one using trie.

geeksforgeeks.org/forum/topic/trie-print-whole-trie-auto-complete-given-a-string-perform-auto-complete?replies=1#post-39421

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

READ IT : "en.wikipedia.org/wiki/Trie"
this data structure is used to do the job you mentioned in question in linear time.

- dabbcomputers January 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Tried would be used just for storing the dictionary. The other major part of the problem is to come up with all the possible letter combinations from the key-presses. Eg. 1 can {A,B,C} etc. ... this can be done using recursion.

int get_possible_characters(int, int&);

void generate_words(int* arr, int begin, int length, char* word=null)
{
	if(begin >= end)
	{
		printf("%s\n",word);
	}
	else
	{
		if(!word)
		{
			word = new char[length];
		}
		int num_candidates;
		char* candidates = get_possible_characters(a[begin], num_candidates);
		for(int i=0; i < num_candidates; i++)
		{
			word[begin] = candidates[i];
			generate_words(arr,begin+1,length,word);
		}
	}
	return;
}

int main()
{
	char* arr = new char[100];
	//Insert values in arr
	generate_words(arr,0,100);
}

- Anonymous January 07, 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