Samsung OA question | 0-5 years

Given two strings s1 and s2 of length n and m, we need to minimize the absolute value of difference between these two strings. For doing so, we can add dummy substrings too in strings to make their length equal. The cost of difference between two different characters at the same index is -4, if one string contains dummy characters then cost is -3 if it's not start of dummy character substring, else -1. For equal characters, cost is 0.
For eg:
s1 = "aaa"
s2 = "b"
Then the minimum difference is -8. since we add dummy substring of length 2. then the difference is -4-3-1 = -8. So, minimum absolute difference possible in our case is 8.

Can anyone please give the solution for the same?

Comments (1)