Google News
logo
Algorithm - Interview Questions
Write down a string reversal algorithm. If the given string is "kitiR," for example, the output should be "Ritik".
An algorithm for string reversal is as follows:
 
Step 1 : Start.
Step 2 : We take two variables l and r.
Step 3 : We set the values of l as 0 and r as (length of the string  - 1).
Step 4 : We interchange the values of the characters at positions l and r in the string.
Step 5 : We increment the value of l by one.
Step 6 : We decrement the value of r by one.
Step 7 : If the value of r is greater than the value of l, we go to step 4
Step 8 : Stop.
Advertisement