Odd Word Reversal
Easy
string
array
Problem Description
Given a sentence, reverse only the words at odd indices (1-indexed). Words are separated by spaces.
Input Format
A single line containing a sentence with words separated by spaces.
Output Format
The sentence with words at odd positions (1st, 3rd, 5th, etc.) reversed.
Constraints
1 <= sentence length <= 1000
Words contain only alphabetic characters
1 <= number of words <= 100
Sample Input/Output
Input:
I love solving coding problems
Output:
I evol solving gnidoc problems
Explanation
Words at positions 1, 3, 5 are: "I", "solving", "problems" (unchanged). Words at positions 2, 4 are: "love" → "evol", "coding" → "gnidoc".
Solution Hints
- Read carefully: Understand input/output format and constraints
- Start simple: Think of brute force solution first, then optimize
- Edge cases: Consider empty inputs, single elements, max constraints
- Data structures: Choose arrays, hash maps, sets based on problem needs
- Time complexity: Ensure your solution fits within time limits
- Test examples: Verify logic with provided sample inputs
80
Points
Points
2000ms
Time Limit
Time Limit
256MB
Memory Limit
Memory Limit
Code Editor
Register to Access Code Editor
Create a free account to solve coding problems and track your progress.
Register Now