Skip to content

Practice Decremental String Concatenation

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2746
LeetCode Problem

Decremental String Concatenation

Problem Statement

Start with words[0]. Process each later word in order, choosing to join it before or after the current string. Joining x and y normally concatenates them, but when x ends with the same character that y begins with, keep only one copy at that boundary. Return the minimum possible final length.

Source: Decremental String Concatenation on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
words = ["aa","ab","bc"]
Output
4

# Example 2

Input
words = ["ab","b"]
Output
2

# Example 3

Input
words = ["aaa","c","aba"]
Output
6

Constraints

1 <= words.length <= 1000
1 <= words[i].length <= 50
Each character in words[i] is an English lowercase letter

Related LeetCode Problems

Practice more problems similar to Decremental String Concatenation.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.