VOOZH about

URL: https://www.geeksforgeeks.org/dsa/interchanging-first-second-halves-stings/

⇱ Interchanging first and second halves of strings - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Interchanging first and second halves of strings

Last Updated : 1 Aug, 2022

Given two strings and . Create two new strings by exchanging the first half and second half of one of the strings with the first half and second half of the other string respectively.

Examples: 

Input : fighter
 warrior
Output :warhter
 figrior

Input :remuneration
 day
Output :dration
 remuneay

In the first example, fighter is made up of two parts fig and hter. Similarly, warrior is also made up of two parts war and rior. Interchange the first part of both the strings to create two new strings warhter and figrior. Similarly, in the second example first part of remuneration which is remune is exchanged with the first part of day to create dration and remuneay.

Implementation:


Output
remuneay
dration

Time Complexity: O(n), time required for substr function
Auxiliary Space: O(n)

Comment
Article Tags:
Article Tags: