Microsoft Interview Question for Software Engineer / Developers






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

you could keep an array of 3 integers that stores the top 3 elements...then in single pass by comparing the current element to these 3 elements we can update the array. the smallest element in this array at the end is 3rd largest

- v December 29, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what do you mean by largest words?(longest word)??

- v_fake December 30, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

yes..longest

- v December 30, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

are you counting length of each word and storing in array of 3 size,there value????

- anurag September 04, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about create a max heap? you can do this in 1 pass

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

Assuming that space is not a constraint:
1) create a max heap in one pass
2) take the top 3 elements off the heap

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

or bitmap?

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

How about using a Prefix Tree of dictionary words and searching through the given string to find the longest word?

- Sonny January 14, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

dude did u have to write the code or just did they expect you to give an idea of ur algo ??

- ranjit February 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

here is the o(n) sol with one pass:

public static void thirdLargest(string[] a)
{string fLarge ="";
string sLarge= "";
string tLarge = "";
string temp = "";
for (int i = 0; i < a.Length; i++)
{


if (a[i].Length > tLarge.Length)
{
tLarge = a[i];

}
if (tLarge.Length > sLarge.Length)
{

swap(tLarge, sLarge);<---write a normal swap function

}
if (sLarge.Length > fLarge.Length)
{
swap(sLarge, fLarge);
}

}

Console.WriteLine("Third Largest:"+ tLarge);
}

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

public static String find3rdLargest(String str) {
char[] ch = str.toCharArray();
int state = 0; //initialized
int count =0;
int noOfSpaces = 0;
int startPos = 0, endPos = 0;

int[] counts = new int[3];
int[] startPoss = new int[3];
int[] endPoss = new int[3];


for(int i=0; i <ch.length; i++) {

// for space (or) end of the array
if(ch[i] == ' ' || i == ch.length -1) {
if(state == 0 || state ==2) {
state=1; //space
if (counts[0] < count) {
counts[2] = counts[1];
endPoss[2] = endPoss[1];
startPoss[2] = startPoss[1];
counts[1] = counts[0];
endPoss[1] = endPoss[0];
startPoss[1] = startPoss[0];
counts[0] = count;
endPoss[0] = i - noOfSpaces;
startPoss[0] = startPos;
} else if (counts[1] < count)
{
counts[2] = counts[1];
endPoss[2] = endPoss[1];
startPoss[2] = startPoss[1];

counts[1] = count;
endPoss[1] = i - noOfSpaces;
startPoss[1] = startPos;

} else if (counts[2] < count)
{
counts[2] = count;
endPoss[2] = i - noOfSpaces;
startPoss[2] = startPos;

}
count = 0;
endPos = i - noOfSpaces;
startPos = i + 1;

} else if(ch[i] == ' '){
noOfSpaces ++;
}


} else {
noOfSpaces = 0;
state =2; //character state
count ++;
}


}

System.out.println(Arrays.toString(counts));
System.out.println(Arrays.toString(startPoss));
System.out.println(Arrays.toString(endPoss));
return str.substring(startPoss[2], endPoss[2]+1);
}

- radhakrishna February 12, 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