Given two strings A and B and these strings contain lower case letters. The task is to tell the length of the merged strings. For example, given A is “abcde” and B is “cdefg”, then merging the two strings results in “abcdefg”. The merge operation is performed in such a manner that the joining characters are both the suffix of A and Prefix of B.
Before merging you are allowed to do any ONE of the following operations:
- Reverse string A
- Reverse string B
Input : A = "ababc" B = "bcabc" Output : Length is 8 the suffix of string A i.e "bc" and prefix of B i.e "bc" is the same so the merged string will be "ababcabc" and length is 8. Input : A = "cdefg" B = "abhgf" Output : Length is 8 the suffix of string A i.e "fg" and prefix of reversed B i.e "fg" is the same so the merged string will be "cdefghba" and length is 8 Input : A = "wxyz" B = "zyxw" Output : Length is 4
Below is the Python code implementation of the above mentioned approach.
Length is 8
- Python | Append suffix/prefix to strings in list
- Python - Swap K suffix with prefix
- Python | Merging two Dictionaries
- Python | Merging two list of dictionaries
- Merging and Updating Dictionary Operators in Python 3.9
- Find the longest common prefix between two strings after performing swaps on second string
- Python | Merging duplicates to list of list
- Python | Merging nested lists
- NLP | Splitting and Merging Chunks
- Python | Split strings in list with same prefix in all elements
- Python | Ways to determine common prefix in set of strings
- Python | Remove prefix strings from list
- Python - Split Strings on Prefix Occurrence
- Python | Segregate list elements by Suffix
- Python | Check if suffix matches with any string in given list
- Python | Check Numeric Suffix in String
- Python - Suffix List Sum
- Python - Find Keys with specific suffix in Dictionary
- Python - Remove suffix from string list
- Python | Extract suffix after K
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.