Problem title
Difficulty
Avg time to solve

Minimum Score
Moderate
30 mins
Design Tic-Tac-Toe
Moderate
30 mins
Make all elements of the array distinct.
Moderate
30 mins
Reverse the order of words in a string
Easy
10 mins
Bounded Blocking Queue
Moderate
25 mins
Maximum Sum Circular Subarray
Moderate
10 mins
Find the City With the Smallest Number of Neighbors at a Threshold Distance
Moderate
15 mins
Minimum Cost to cross Grid
Moderate
30 mins
Find K Closest Elements
Moderate
15 mins
Subtract The Product And Sum Of Digits Of An Integer
Easy
10 mins
3

# Reverse the order of words in a string

Difficulty: EASY
Contributed By
Avg. time to solve
10 min
Success Rate
90%

Problem Statement

#### Note: Try to do it in-place without allocating extra space.

##### Example:
‘STR’ = “when in doubt use brute force”
The reverse order of words in ‘STR’ is: “force brute use doubt in when”.
##### Note:
1. ‘STR’ does not contain any leading or trailing spaces.
2. The words are always separated by a single whitespace character.
##### Input format:
The first line of input contains an integer ‘T’ which denotes the number of test cases. Then, the ‘T’ test cases follow.

The first line and only line of each test case contain a single string ‘STR’.
##### Output format:
For every test case, return a string with the reverse orders of words as ‘STR’.
##### Note:
You do not need to print anything; it has already been taken care of. Just implement the function.
##### Constraints:
1 <= T <= 100
1 <= Length of ‘STR’ <= 10^3
The string ‘STR’ contains only ‘a-z’ and whitespace characters.

Time limit: 1 second

#### Sample input 1:

2
when all else fails reboot
java is to javascript what a car is to carpet

#### Sample output 1:

reboot fails else all when
carpet to is car a what javascript to is java

#### Explanation of sample input 1:

Test Case 1:
‘STR’ = “when all else fails reboot”
The reverse order of words in ‘STR’ is: “reboot fails else all when”.

Test Case 2:
‘STR’ = “java is to javascript what a car is to carpet”
The reverse order of words in ‘STR’ is: “carpet to is car a what javascript to is java”.

#### Sample input 2:

2
no code has zero defects
whitespace is never white

#### Sample output 2:

defects zero has code no
white never is whitespace
Console