Tap here to switch tabs
Problem
Submissions

Problem: Decremental String Concatenation

med
30 min
Try to solve the Decremental String Concatenation problem.

Statement

You are given a 00 indexed array of strings words.

Define a function join(s1, s2) that concatenates two strings s1 and s2 in the following manner:

  • If the last character of s1 is identical to the first character of s2, the two overlapping characters merge into one.

  • Otherwise, s1 and s2 are simply concatenated together.

Starting with str0=_0 = words[0][0], you must perform n−1n - 1 steps, where nn is the length of words. For each index i from 11 to n−1n - 1, you can set stri_i to either:

  • join(stri−1_{i - 1}, words[i])

  • join(words[i], stri−1_{i - 1})

Return the minimum possible length of strn−1_{n - 1} after completing all operations.

Constraints:

  • 1≤1 \leq words.length ≤1000\leq 1000

  • 1≤1 \leq words[i].length ≤50\leq 50

  • Each character in words[i] is a lowercase English letter.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Decremental String Concatenation

med
30 min
Try to solve the Decremental String Concatenation problem.

Statement

You are given a 00 indexed array of strings words.

Define a function join(s1, s2) that concatenates two strings s1 and s2 in the following manner:

  • If the last character of s1 is identical to the first character of s2, the two overlapping characters merge into one.

  • Otherwise, s1 and s2 are simply concatenated together.

Starting with str0=_0 = words[0][0], you must perform n−1n - 1 steps, where nn is the length of words. For each index i from 11 to n−1n - 1, you can set stri_i to either:

  • join(stri−1_{i - 1}, words[i])

  • join(words[i], stri−1_{i - 1})

Return the minimum possible length of strn−1_{n - 1} after completing all operations.

Constraints:

  • 1≤1 \leq words.length ≤1000\leq 1000

  • 1≤1 \leq words[i].length ≤50\leq 50

  • Each character in words[i] is a lowercase English letter.