Top K Frequently Mentioned Keywords
Given a list of
reviews, a list of
keywords and an integer
k. Find the most popular
k keywords in order of most to least frequently mentioned.
The comparison of strings is case-insensitive.
Multiple occurances of a keyword in a review should be considred as a single mention.
If keywords are mentioned an equal number of times in reviews, sort alphabetically.
The input consists of three arguments:
k: an integer
keywords: a list of strings representing the keywords
reviews: a list of strings that consists of
space-sperated words representing sentences
Return a list of strings of most popular
k keywords in order of most to least frequently mentioned
keywords = ["anacell", "cetracular", "betacellular"]
reviews = [ "Anacell provides the best services in the city", "betacellular has awesome services", "Best services provided by anacell, everyone should use anacell", ]
anacell is occuring in
2 different reviews and
betacellular is only occuring in
keywords = ["anacell", "betacellular", "cetracular", "deltacellular", "eurocell"]
reviews = [ "I love anacell Best services; Best services provided by anacell", "betacellular has great services", "deltacellular provides much better services than betacellular", "cetracular is worse than anacell", "Betacellular is better than deltacellular.", ]
betacellular is occuring in
3 different reviews.
deltacellular are occuring in
2 reviews, but
anacell is lexicographically smaller.