Interview Questions

Microsoft Interview for Software Engineer in Manager Round

Manager Round interview Questions and Answers


(Continued from previous question...)

Microsoft Interview for Software Engineer in Manager Round

Q:
How do you find the 3rd largest word in a given string that is millions of characters long and he wanted me to give a solution in only one pass ?

An:
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);

(Continued on next question...)

Other Interview Questions