Interview Question

Junior Software Engineer Interview Richmond, BC (Canada)

Write a function that reverses the order of words in a


Interview Answer

1 Answer


Assuming they're using C#

string sentence = Console.ReadLine(); // Assign input to string
string[] sentenceWords = sentence.Split(' '); // Assign words sequentially into an array
Array.Reverse(sentenceWords); // Reverse array
Console.WriteLine(String.Join(" ", sentenceWords)); // Show result

Matt Carter on Jun 20, 2013

Add Answers or Comments

To comment on this, Sign In or Sign Up.