VOOZH about

URL: https://www.geeksforgeeks.org/dsa/string-from-prefix-and-suffix-of-given-two-strings/

⇱ String from prefix and suffix of given two strings - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

String from prefix and suffix of given two strings

Last Updated : 18 Nov, 2022

Given two strings a and b, form a new string of length l, from these strings by combining the prefix of string a and suffix of string b.

Examples : 

Input : string a = remuneration
 string b = acquiesce
 length of pre/suffix(l) = 5
Output :remuniesce

Input : adulation
 obstreperous
 6
Output :adulatperous

Approach : 

  1.  Get first l letters from string a, and last l letters from string b. 
  2. Combine both results, and this will be resultant string.

Implementation:


Output
remuniesce

Time Complexity: O(n + m), where n and m are the lengths of the given string.
Auxiliary Space: O(n + m), where n and m are the lengths of the given string.

Comment
Article Tags:
Article Tags: