Class Solution
-
- All Implemented Interfaces:
public final class Solution3598 - Longest Common Prefix Between Adjacent Strings After Removals.
Medium
You are given an array of strings
words. For each indexiin the range[0, words.length - 1], perform the following steps:Remove the element at index
ifrom thewordsarray.Compute the length of the longest common prefix among all adjacent pairs in the modified array.
Return an array
answer, whereanswer[i]is the length of the longest common prefix between the adjacent pairs after removing the element at indexi. If no adjacent pairs remain or if none share a common prefix, thenanswer[i]should be 0.Example 1:
Input: words = "jump","run","run","jump","run"
Output: 3,0,0,3,3
Explanation:
Removing index 0:
Removing index 1:
Removing index 2:
Removing index 3:
Removing index 4:
Example 2:
Input: words = "dog","racer","car"
Output: 0,0,0
Explanation:
Removing any index results in an answer of 0.
Constraints:
<code>1 <= words.length <= 10<sup>5</sup></code>
<code>1 <= wordsi.length <= 10<sup>4</sup></code>
words[i]consists of lowercase English letters.The sum of
words[i].lengthis smaller than or equal <code>10<sup>5</sup></code>.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntArraylongestCommonPrefix(Array<String> words)-
-
Method Detail
-
longestCommonPrefix
final IntArray longestCommonPrefix(Array<String> words)
-
-
-
-