Skip to content

Practice Longest Common Prefix Between Adjacent Strings After Removals

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

Medium#3598
LeetCode Problem

Longest Common Prefix Between Adjacent Strings After Removals

Problem Statement

For each index i independently, remove words[i] and measure the common-prefix length of every adjacent pair remaining. Return the largest of those lengths, or zero if there is no adjacent pair or all lengths are zero. Collect one result per original index.

Source: Longest Common Prefix Between Adjacent Strings After Removals on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
words = ["jump","run","run","jump","run"]
Output
[3,0,0,3,3]

# Example 2

Input
words = ["dog","racer","car"]
Output
[0,0,0]

Constraints

1 <= words.length <= 10^5
1 <= words[i].length <= 10^4
words[i] consists of lowercase English letters.
The sum of words[i].length is smaller than or equal 10^5.

Related LeetCode Problems

Practice more problems similar to Longest Common Prefix Between Adjacent Strings After Removals.

Review your practice with PhantomCodeAI

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