first, second and third. In one operation you pick any of them and delete its last character, but a string may never become empty.
Return the fewest operations after which all three strings are equal, or -1 if that cannot be done.first='plant', second='plan', third='planet' → 3
Trim plant to plan (1 operation) and planet to plan (2 operations): 3 in total.
first='sun', second='sun', third='sun' → 0
The strings already match.
first='cat', second='cot', third='bat' → -1
The first letters differ and no string may be erased completely, so the answer is -1.
first='plant', second='plan', third='planet'
3
Run checks the first 3 tests in your browser. Submit checks all 128 tests on the server, hidden ones included.