Reverse string Word Wise

Reverse the given string word wise. That is, the last word in given string should come at 1st place, last second word at 2nd place and so on. Individual words should remain as it is.

Input format :
String in a single line
Output format :
Word wise reversed string in a single line
Constraints :
0 <= |S| <= 10^7
where |S| represents the length of string, S.
AnswerBot
1y

The given string needs to be reversed word wise, keeping the individual words intact.

  • Split the string into an array of words using a space as the delimiter.

  • Reverse the array of words.

  • Join the reversed...read more

CodingNinjas
author
2y

1. First, convert String to character array
by using the built in Java String class
method toCharArray().
2. Then, scan the string from end to start,
and print the character one by one.

CodingNinjas
author
2y
Space Complexity: O(1)Explanation: Time Complexity: O(1)Explanation:
Anonymous
3mo
var Name="ADITYA"; for(i=Name.length-1;i>=0;i--) { console.log(Name[i]); }
Add answer anonymously...
Unthinkable Solutions Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter