Array ( [0] => [1] => questions [2] => Strings [3] => Reverse-of-String )
Given a string K. You have to find the reverse of given string.
First line contains the string K.
Print the reverse string.
educate
etacude
never giveup
puevig reven
he is my favourite hero
oreh etiruovaf ym si eh
Login to see Discussion
Approach 1: Using loop
i)create an empty string answer
ii) traverse the given string in reverse order and append the characters to the answer
iii) return the answer
Time Complexity: O(n)
Space Complexity: O(n)
Approach 2: using Built in method
i)convert the given string to string builder
ii)reverse the string builder by calling builtin method reverse
iii) convert string builder to string and return it
Time Complexity: O(n)
Space Complexity: O(n)
Note :
Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.
Login to see Solution