BackmediumStrings Infosys

Interior Word Reversal Solution

Problem Statement

You are given a sequence of words as a sentence. Reverse the order of all words except the first and last word, and return the modified sentence.

Example 1
Input
the dog runs quickly outside
Output
the quickly runs dog outside

Explanation: Reversing the middle words 'dog runs quickly' results in 'quickly runs dog'.

Constraints

  • 1 <= sentence length <= 100
  • 1 <= word length <= 20
  • The input sentence contains only lowercase letters and spaces.
  • The input sentence does not start or end with a space.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free