FastPrepMost Frequent Word across Grouped Arrays

Most Frequent Word across Grouped Arrays

ZipRecruiter logoZipRecruiter● EasyNEW GRADPHONE SCREEN
Learn

Problem statement

Count every word occurrence across all rows of groups. Return the word with highest frequency, breaking ties lexicographically. Matching is case-sensitive. Return an empty string when there are no words.

Function

mostFrequentWord(groups: String[][]) → String

Examples

Example 1

groups = [["a","b"],["a","c"]]return = "a"

Word a occurs twice across rows.

Example 2

groups = [["beta"],["alpha"]]return = "alpha"

Lexicographic order resolves equal frequency.

Constraints

  • 0 <= groups.length <= 10000
  • The total number of words is at most 100000.

More ZipRecruiter problems

See ZipRecruiter hiring insights
public String mostFrequentWord(String[][] groups) {
    // Write your code here.
}
groups[["a","b"],["a","c"]]
expected"a"
Checking account…