Microsoft Interview Question for Software Engineer in Tests






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

question is not clear.
Does the substring should be longest? otherwise, just find the first repeated character in the given string. This can be done in O(n) by hashing.

- Anonymous October 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Its the first repeated substring
For ABCBDA - answer is A, A is first repeated substring
For ABCBCBCD - answer is BC(if substring should not overlap) and BCBC(if substrings can overlap)

- Erik October 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

ABCBDA -- answer is B, right?
ABCBCBCD -- why not B? Why BC or even BCBC? What's the criteria here? Once I have a candidate, should I find the longest one?

Anyway, Prashanth's solution should work no matter what :-)

- czpete October 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

You can add each individual letter to an array list.
As you keep adding, if you find a letter that already exists, check to see if the next letter matches the next letter of the previously matching letter, until you find a letter that does not match.

That should do the trick

- Prashanth October 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Whats the trick here? Straight forward N^2 solution.

Suffix trees should be used.

- Mahesh October 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Just an extension to Prashanth's algorithm to improve complexity. Use a hash map for storing the locations for each alphabet <key,value> => <alphabet,arrayOfLocations>. Everytime we find an existing alphabet we insert the new location at the end of existing arrayOfLocations for that alphabet. So that when we want to access an alphabet of same type we dont have to go through the array from beginning, we can access using hash map in constant time.
Again, correct me if am wrong

- chennavarri October 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

please provide a example for your implementation. I think Prashanth solution is ok. But how to deal with overlap case?

- sniperswang October 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I like this solution.

- Prashanth October 14, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I had the same idea.

- Anonymous October 14, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

But if there are many same letter, "ABCAABGRAVBARQAA..."
How do you map "A"? map and chaining?

- Sam October 14, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

As far as I understand, Prashanth's algorithm has O(NxN) complexity. I think you can do it using suffix tree for O(N), but it's hard to implement on the interview :)

- Sergey October 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hi...

Can you please explain how it would be O(N*N).

Thank you

- Prashanth October 14, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Let's think the MATCHED substring is end of the array.
With this string "AbcdefghjklmnopqrstuvwxyzA"
Your temp array going to be increased like "Abcdefghjklmnopqrstuvwxyz" worst case is N * N

- Sam October 14, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Ahh... I see... So how can we do it in O(N) Complexity

- King October 14, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Are we not missing something here? The solution is not straight forward using this approach. What if 'A' appears multiple times in the input string. Each sub-string starting with 'A' should be matched against all other substrings.

- SPD October 17, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

SuffixTreeNode * root = makeSuffixTree(str);

String firstLongestRepeating = findLongestBranchWithTwoLeaves(root);

- dumber October 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can you guys please look at this too.

This Problem has to be solved recursively
So the Problem being this.
Given a particular number say 637-8687 (NERVOUS) would be the word.
So for the older keypad’s seen on telephone’s I would have to create Mnemonics.
So for doing this, the first part being list out all the Permutations possible for a particular number series.
Ex: ListMnemonics(“723″) would result in
PAD PBD PCD QAD QBD QCD RAD RBD RCD SAD SBD SCD
PAE PBE PCE QAE QBE QCE RAE RBE RCE SAE SBE SCE
PAF PBF PCF QAF QBF QCF RAF RBF RCF SAF SBF SCF
For this my logic is
for the above number 723, somehow create all the permutations for 23 and then append for each of those permutations the letters of 7. That would give all the permutations possible for 723. The base case being if there is a single number then I would print its letters.
But please let me know what you guys think

- Prashanth October 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It is simple question just do it.

char keyMap[10][5] = {"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};

void rcsv_KeyPermute(char *keyNum, char *buf, int level, int end)
{
	char *keys = keyMap[ *keyNum - '0' ];
	char ch;
	while( (ch = *keys++) != NULL )
	{
		*(buf + level) = ch;
		if( level != end )
		{
			rcsv_KeyPermute( keyNum+1, buf, level+1, end );
		}
		else
		{
			*(buf + level + 1) = NULL;
			cout << buf << " ";
		}
	}
}

void KeypadPermute(char *numbers)
{
	int length = strlen(numbers);
	char buf[100];
	rcsv_KeyPermute(numbers, buf,0, length-1);
}

- Sam October 14, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use preprocessing step of KMP starting at every position i - O(n^2) ?

- Anonymous October 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a

- a October 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can use suffix trees to find repeated substrings. Along with the end node in the suffix tree we can also store start index of the string. So in the case of non-overlapping sub-strings we can see whether index + length > other index :)

- Ashish Kaila June 20, 2011 | 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