Practice Longest Common Prefix of K Strings After Removal
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given an array of strings words and an integer k. For each index i in the range [0, words.length - 1], find the length of the longest common prefix among any k strings (selected at distinct indices) from the remaining array after removing the ith element. Return an array answer, where answer[i] is the answer for ith element. If removing the ith element leaves the array with fewer than k strings, answer[i] is 0.
Source: Longest Common Prefix of K Strings After Removal on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
words = ["jump","run","run","jump","run"], k = 2
[3,4,4,3,4]
# Example 2
words = ["dog","racer","car"], k = 2
[0,0,0]
Constraints
Related LeetCode Problems
Practice more problems similar to Longest Common Prefix of K Strings After Removal.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.