Microsoft

  www.microsoft.com
Work in HR? Unlock Free Profile

Microsoft Software Development Engineer Intern Interview Question

I interviewed in Seattle, WA and was asked:
"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."
Add Tags [?]
Answer

Part of a Software Development Engineer Intern Interview Review - one of 3,411 Microsoft Interview Reviews

Answers & Comments

1
of 3
votes

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

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.