Tap here to switch tabs
Problem
Submissions

Problem: Longest Common Prefix of K Strings After Removal

Try to solve the Longest Common Prefix of K Strings After Removal problem.

Statement

You are given an array of strings words and an integer k.

For each index i from 00 to words.length −1- 1, consider the list of strings remaining after removing words[i]. Find the maximum length of a common prefix shared by any k strings chosen from this remaining list. If it is impossible to choose k strings that share a common prefix of positive length, the maximum length is 00.

Return an integer array ans of size words.length, where ans[i] is the maximum common prefix length among any k strings after removing words[i].

Constraints:

  • 1≤1 \le k ≤\le words.length ≤105\le 10^5

  • 1≤1 \le words[i].length ≤104\le 10^4

  • words[i] consists of lowercase English letters.

  • The sum of words[i].length is smaller than or equal to 10510^5.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Longest Common Prefix of K Strings After Removal

Try to solve the Longest Common Prefix of K Strings After Removal problem.

Statement

You are given an array of strings words and an integer k.

For each index i from 00 to words.length −1- 1, consider the list of strings remaining after removing words[i]. Find the maximum length of a common prefix shared by any k strings chosen from this remaining list. If it is impossible to choose k strings that share a common prefix of positive length, the maximum length is 00.

Return an integer array ans of size words.length, where ans[i] is the maximum common prefix length among any k strings after removing words[i].

Constraints:

  • 1≤1 \le k ≤\le words.length ≤105\le 10^5

  • 1≤1 \le words[i].length ≤104\le 10^4

  • words[i] consists of lowercase English letters.

  • The sum of words[i].length is smaller than or equal to 10510^5.