Interview Question

Junior Software Engineer Interview

-Richmond, BC

MDA

Write a function that reverses the order of words in a sentence.

Answer

Interview Answers

2 Answers

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

0

C implementation... Copy the sentence into a character array. Reverse all the characters in the array, then reverse the characters for each word. Word separator is space.

Theo on

Add Answers or Comments

To comment on this, Sign In or Sign Up.