Question bank › Strings
Dsa Strings Warm-up

Reverse Words in a Sentence

Given a sentence composed of words separated by spaces, you need to reverse the order of the words while maintaining the original spacing. Consider leading and trailing spaces as well as multiple consecutive spaces. Input: - A single line containing the sentence. Output: - The sentence with the words reversed and spaces intact. Example: Input: " Hello world " Output: " world Hello "

Key concepts

stringsmanipulationtrimming

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.