Coding Interview Question: Reversing the Words in a String

In today’s coding exercise the task is to reverse the words in a string, where words are separated by one or more spaces.

Summary

Build a program that reverses the words in a string, where words are separated by one or more spaces.

Exercise File

Code File

Exercise Description

Given the following strings:

"dog lazy the over jumped fox brown quick The"

Write a program that reverses the order of the words.

Sample Input

"dog lazy the over jumped fox brown quick The"

Sample Output

"The quick brown fox jumped over the lazy dog"

Real World Usage

This is a very common Ruby coding interview question since it tests knowledge of how to works with strings, arrays, and how they can work together.

Solution

Can be found on the solutions branch on github.

Jordan Hudgens

view all post
Leave a comment

Please be polite. We appreciate that.

By Daniele Zedda • 18 February

← PREV POST

By Daniele Zedda • 18 February

NEXT POST → 34
Share on