Skip to content

Latest commit

 

History

History
10 lines (6 loc) · 617 Bytes

Sentence_Reverse.md

File metadata and controls

10 lines (6 loc) · 617 Bytes

#Sentence Reverse

You are given an array of characters arr, which consists of sequences of characters separated by space characters. Each space-delimited sequence of characters defines a word. How can you most efficiently reverse the order of the words in the array? Explain and implement your solution. Lastly, analyze its time and space complexities.

For example:

[ 'p', 'e', 'r', 'f', 'e', 'c', 't', ' ', 'm', 'a', 'k', 'e', 's', ' ', 'p', 'r', 'a', 'c', 't', 'i', 'c', 'e' ] would turn into:

[ 'p', 'r', 'a', 'c', 't', 'i', 'c', 'e', ' ', 'm', 'a', 'k', 'e', 's', ' ', 'p', 'e', 'r', 'f', 'e', 'c', 't' ]