Find Dominance
In an Amazon content analysis project, there is a dataset of strings, each representing distinct attributes. The goal is to determine the dominance of the most influential attribute prefix for various lengths.
The dominance of a prefix, denoted as t, is measured by the number of instances in the dataset where t serves as a prefix. For example, in the dataset ["abab","ababc","abab"], the dominance of the prefix "ab" is 3, and the dominance of the prefix "aba" is 3.
The most influential prefix of a specific length len is identified as the prefix with the highest dominance among all strings of the same length. If there are multiple prefixes of the same length with equivalent dominance, any prefix from that set may be considered the most influential.
Formally, given the dataset s consisting of n strings, each of length m, the objective is to determine, for each prefix of length len ranging from 1 to m, the dominance of the most influential prefix of that length.
Complete the function findDominance in the editor below.
findDominance has the following parameters:
string s[]: The array of strings
Returns
int[]: the dominance of the most influential prefix of lengths from 1 to m
Constraints
- 2 β€
nβ€ 500 - 1 β€
mβ€ 2000
π³ 1004 thanks to spike!π Truly grateful! π
1Example 1
2Example 2
Constraints
Limits and guarantees your solution can rely on.
2 β€ n β€ 5001 β€ m β€ 2000