![]() |
VOOZH | about |
Write a program to reverse a given word.
Examples:
Input: "Hello"
Output: "olleH"Input: "Programming"
Output: "gnimmargorP"
Approach: To solve the problem, follow the below idea:
It can be observed that we can reverse a word by traversing over the original string in reverse order and then pushing the characters from the back to a new string. Finally, return the final string.
Step-by-step algorithm:
Below is the implementation of the algorithm:
Original Word: Hello Reversed Word: olleH
Time Complexity: O(N) where N is the length of the word.
Auxiliary Space: O(N)