Problem Solving: Reversing the Strings

Reversing the string and its variants

Let’s solve multiple variants of reversing the string:

Exercise 1: Reversing the range

Write a function that takes a string and the start and end indexes of the range as inputs and reverses the string within that range. This function is an extension of this lesson.

Test the function on the provided main in the playground:

Sample input

Before reversing: S = 'THIS is A WORLD OF C++'

Sample output

After reverse(S, 0, 3): S = 'SIHT is A WORLD OF C++'
After reverse(S, 0, 3): S = 'THIS is A WORLD OF C++'
After reverse_all(S):   S= '++C FO DLROW A si SIHT'

Get hands-on with 1200+ tech skills courses.