You are given two lines A and B, and these lines contain lowercase letters. The challenge is to specify the length of the merged strings. For example, if A — “Abcde”, and B — “Cdefg” then concatenation of the two strings results in “abcdefg”. The merge operation is performed such that the characters to be appended are suffix A and prefix B.
Before merging, you are allowed to perform ONE of the following operations:
Input: strong> A = "ababc" B = "bcabc" Output: Length is 8 the suffix of string A ie "bc" and prefix of B ie "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 ie "fg" and prefix of reversed B ie "fg" is the same so the merged string will be "cdefghba" and length is 8 Input: A = "wxyz" B = "zyxw" Output: strong> Length is 4
Below is the Python code implementation of the above approach.