You work on the Kindle team and are trying to understand which features users want added to a new version of the Kindle the most. Your team has received a large number of feature requests from users.
Write an algorithm that identifies the most popular N feature requests out of a list of feature requests and possible features. Your algorithm should output the most-frequently mentioned features.
Input
The input to the function/method consists of three arguments -
topFeatures, an integer representing the number of top features that your function returns (N);
possibleFeatures, a list of single-word strings representing possible features;
featureRequests, a list of strings where each element is a string that consists of space-separated words representing feature requests.
Output
Return a list of strings representing a list of strings of the most popular N features requests in order of most to least frequently mentioned.
Note
The comparison of strings is case-insensitive.
If the value of topFeatures is more than the number of possible features, return the names of only the features mentioned in the feature requests.
If features are mentioned an equal number of times in feature requests (eg. screen=2, solar=2, battery=4), sort alphabetically. topNFeatures=2, Output= [battery, screen]
Example
Input:
topFeatures = 2
possibleFeatures = ["storage", "battery", "hover", "alexa", "waterproof", "solar"]
featureRequests = ["I wish my Kindle had even more storage!", "I wish the battery life on my Kindle lasted 2 years.", "I read in the bath and would enjoy a waterproof Kindle", "Waterproof and increased battery are my top two requests", "I want to take my Kindle into the shower. Waterproof please!", "It would be neat if my Kindle would hover on my desk when not in use", "How cool would it be if my Kindle charged in the sun via solar power?"]
Output:
["waterproof", "battery"]
Explanation:
"waterproof" occurs in three different requests and "battery" in two. "Hover", "solar", and "storage" occur in only one request each.