FastPrepTop Counted Word Records

Top Counted Word Records

Indeed logoIndeed● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Each string in records contains a word and its count, separated by one comma. Return the highest-count records whose word length is at least minWordLength, with at most wordLimit results.

For this exercise, assume surrounding ASCII spaces in each field are ignored. Every input occurrence is a separate record: duplicate words and identical records are preserved, and counts are neither added nor overwritten.

For this exercise, assume records sort by descending count, then case-sensitive ASCII word order, then earlier input index. Return each selected record as its trimmed word, a comma and one space, and its count in canonical decimal form. Empty input, no eligible records or a zero limit returns an empty array.

Function

getTopWords(records: String[], wordLimit: int, minWordLength: int) → String[]

Examples

Example 1

records = ["abc, 500","sadhasjhkgdsak, 230239203","fsgdfssd, 78","sss, 56","ss, 56","sss, 5678 ","sssdsds, 56","ssssdsd, 56"]wordLimit = 3minWordLength = 3return = ["sadhasjhkgdsak, 230239203","sss, 5678","abc, 500"]

The three highest eligible records are sadhasjhkgdsak with 230239203, sss with 5678, and abc with 500. The three-letter abc meets the minimum length.

Example 2

records = ["cat, 7","ant, 7","dog, 8","a, 100"]wordLimit = 2minWordLength = 3return = ["dog, 8","ant, 7"]

The short a record is excluded. Dog ranks first by count; ant wins the seven-count cutoff tie by ASCII word order.

Constraints

  • For this exercise, assume 0 <= records.length <= 500, 0 <= wordLimit <= 500 and 0 <= minWordLength <= 31.
  • Every record has exactly one comma. For this exercise, assume each trimmed word has 1 through 30 ASCII letters, and each count has 1 through 10 decimal digits with value from 0 through 1000000000.
  • For this exercise, assume each field may have up to two ASCII spaces before and after it. Leading zeros in a count are accepted; word comparison is case-sensitive.

More Indeed problems

See Indeed hiring insights
public String[] getTopWords(String[] records, int wordLimit, int minWordLength) {
    // Write your code here.
    return new String[0];
}
records["abc, 500","sadhasjhkgdsak, 230239203","fsgdfssd, 78","sss, 56","ss, 56","sss, 5678 ","sssdsds, 56","ssssdsd, 56"]
wordLimit3
minWordLength3
expected["sadhasjhkgdsak, 230239203", "sss, 5678", "abc, 500"]
Checking account…