You are given an array of strings words
. For each index i
in the range [0, words.length - 1]
, perform the following steps:
i
from the words
array.Return an array answer
, where answer[i]
is the length of the longest common prefix between the adjacent pairs after removing the element at index i
. If no adjacent pairs remain or if none share a common prefix, then answer[i]
should be 0.
Example 1:
Input: words = ["jump","run","run","jump","run"]
Output: [3,0,0,3,3]
Explanation:
words
becomes ["run", "run", "jump", "run"]
["run", "run"]
having a common prefix "run"
(length 3)words
becomes ["jump", "run", "jump", "run"]
words
becomes ["jump", "run", "jump", "run"]
words
becomes ["jump", "run", "run", "run"]
["run", "run"]
having a common prefix "run"
(length 3)["jump", "run", "run", "jump"]
["run", "run"]
having a common prefix "run"
(length 3)Example 2:
Input: words = ["dog","racer","car"]
Output: [0,0,0]
Explanation:
Constraints:
1 <= words.length <= 105
1 <= words[i].length <= 104
words[i]
consists of lowercase English letters.words[i].length
is smaller than or equal 105
.