AWS Hiring Challenge | Min Length For Merged String
Anonymous User
1174

You are given two strings A and B. You need to merge these strings, considering all characters that are both prefix of A and suffix of B once.

For example: A = "abcde", B = "cdefg", merged string = "abcdefg".

Before merging, any one of the following operations can be performed at max once:

  • reverse A
  • reverse B
  • add 1 char at the end of A
  • add 1 char at the beginning of B

Print the minimum length possible for the merged string.

Constraints:
1 <= T <= 1000 (no of test cases)
1 <= |A|, |B| <= 10^4

Examples:
2 (no of test cases)
ababc
bcabc
cdefg
abhgf

Output:
8
8

Explanation:

  1. Perform no operation, merged string: ababcabc.
  2. Reverse B, merged string: cdefghba.

Taken from: here.

Comments (2)