Your question is Reverse Words With Single Spaces. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
The Zomato app may receive a search query containing leading spaces, trailing spaces, or multiple spaces between words. Given such a string, return a new string with the words in reverse order, separated by exactly one space, with no leading or trailing spaces.
A word is a maximal sequence of non-space characters. Only the space character is considered a separator.
Implement reverse_words(s), where s is a string and the return value is a string. Preserve every word exactly, but reverse their order and normalize the separators.
def reverse_words(s):