Microsoft Interview Question: Reveres all the words in a st... | Glassdoor

Interview Question

Software Development Engineer Intern 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));


andrejev2006 on Feb 13, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.