Interview Question

Junior Software Engineer Interview Richmond, BC (Canada)

Write a function that reverses the order of words in a

  sentence.
Answer

Interview Answer

1 Answer

0

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 question, Sign In with Facebook or Sign Up