← AlgoMindset 75

Reverse Words in a String

Medium🎙 Interview me on this

🧠 Before you code — what pattern fits?

Given an input string s, reverse the order of the words. A word is a maximal substring of non-space characters. Return a string with the words in reverse order joined by a single space, with no leading or trailing spaces.

"the sky is blue" → "blue is sky the"

" hello world " → "world hello"

🎬 Video explanation · Knowledge Center

Your solution runs against 3 unit tests, including edge and large-value cases.

Loading...

Test console · 3 unit tests

Submit your code to run it against all 3 unit tests. Results appear here.

JavaScript, TypeScript & Python run sandboxed in your browser; other languages run on the execution server. Your code is saved locally as you type.