-
Notifications
You must be signed in to change notification settings - Fork 21k
Open
Labels
Description
What would you like to Propose?
The implementation returns the k most frequent words from an input array.
https://en.wikipedia.org/wiki/Top-k_problem
Test Case (feature demonstration)
Input:
String[] words = {"the", "day", "is", "sunny", "the", "the", "the", "sunny", "is", "is"};
int k = 4;
Expected output:
["the", "is", "sunny", "day"]
Issue details
Algorithm details:
- Input: array of words String[] words and integer k.
- Output: list of the top k most frequent words.
- Ordering:
- Higher frequency first.
- If frequencies are equal, lexicographically smaller word first.
- Behavior:
- If k == 0 or input array is empty, return empty list.
- If k is greater than number of unique words, return all unique words in ranked order.
- Validation:
- Throws IllegalArgumentException when:
- words is null
- k < 0
- any element in words is null
- Throws IllegalArgumentException when:
Additional Information
No response
Reactions are currently unavailable