JuniorString

Make Three Strings Equal

You are given three strings: s1, s2, and s3. In one operation you can choose one of these strings and delete its rightmost character. Note that you cannot completely empty a string.

Return the minimum number of operations required to make the strings equal. If it is impossible to make them equal, return -1.

Example 1
Inputs1 = "abc", s2 = "abb", s3 = "ab"
Output2
Deleting the rightmost character from both s1 and s2 will result in three equal strings.
Example 2
Inputs1 = "dac", s2 = "bac", s3 = "cac"
Output-1
Since the first letters of s1 and s2 differ, they cannot be made equal.

Constraints

  • 1 <= s1.length, s2.length, s3.length <= 100
  • s1, s2 and s3 consist only of lowercase English letters.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate