Class Solution
-
- All Implemented Interfaces:
public final class Solution3485 - Longest Common Prefix of K Strings After Removal.
Hard
You are given an array of strings
wordsand an integerk.For each index
iin the range[0, words.length - 1], find the length of the longest common prefix among anykstrings (selected at distinct indices ) from the remaining array after removing the <code>i<sup>th</sup></code> element.Return an array
answer, whereanswer[i]is the answer for <code>i<sup>th</sup></code> element. If removing the <code>i<sup>th</sup></code> element leaves the array with fewer thankstrings,answer[i]is 0.Example 1:
Input: words = "jump","run","run","jump","run", k = 2
Output: 3,4,4,3,4
Explanation:
Removing index 0 (
"jump"):Removing index 1 (
"run"):Removing index 2 (
"run"):Removing index 3 (
"jump"):Removing index 4 ("run"):
Example 2:
Input: words = "dog","racer","car", k = 2
Output: 0,0,0
Explanation:
Removing any index results in an answer of 0.
Constraints:
<code>1 <= k <= 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>.