Want a Free Job Posting?

Buy a job posting today and the second one is on us. For a limited time only. Act Now.

Interview Question

Interview Seattle, WA

Reveres all the words in a string before you encounter a

  word which has 'x' in it. Hi, I like Microsoft asdfxab Settle -> Microsoft like I Hi, asdfxab seattle.

Interview Answer

1 Answer


using System; using System.Linq; namespace ReverseWords { class Program { static void Main() { const string inputStr = "Hi, I like Microsoft asdfxab Settle"; string reversedStr = String.Join(" ", inputStr.Split(' ').TakeWhile(n => !n.Contains("x")).Reverse()); string resultStr = String.Concat(reversedStr, inputStr.Substring(reversedStr.Length)); Console.WriteLine(resultStr); } } }

andrejev2006 on Feb 13, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.