Dev
Mentor
Coach Interview AI
Mock Interview AI
Coding Problems
Blog
Pricing
Toggle theme
Sign In
Get Started
Toggle theme
Loading...
For the best coding experience, use a desktop browser.
Medium
String
Reverse Words in a String
Reverse the order of words in a string and trim extra spaces.
Examples
Input:
s = "the sky is blue"
Output:
"blue is sky the"
Sample Test Cases
Case 1 Input:
"the sky is blue"
Expected:
"blue is sky the"
Case 2 Input:
" hello world "
Expected:
"world hello"
Reset
Run
Submit
Loading editor...
Test Case
Output
Submission
Case 1 Input:
"the sky is blue"
Expected:
"blue is sky the"
Case 2 Input:
" hello world "
Expected:
"world hello"