2746. Decremental String Concatenation
You are given a 0-indexed array
words
containingn
strings.Let’s define a join operation
join(x, y)
between two stringsx
andy
as concatenating them intoxy
. However, if the last character ofx
is equal to the first character ofy
, one of them is deleted.For example
join("ab", "ba") = "aba"
andjoin("ab", "cde") = "abcde"
.You are to perform
n - 1
join operations. Letstr0 = words[0]
. Starting fromi = 1
up toi = n - 1
, for theith
operation, you can do one of the following:
- Make
stri = join(stri - 1, words[i])
- Make
stri = join(words[i], stri - 1)
Your task is to minimize the length of
strn - 1
.Return an integer denoting the minimum possible length of
strn - 1
.
1 | class Solution { |