Interview Questions

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 ?

Microsoft Interview Questions and Answers


(Continued from previous question...)

6. 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 ?

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