You're a product manager analyzing user feedback for your latest software release! ๐
You have a list of features in your product and a collection of user responses from surveys. Each response contains space-separated feature names that users mentioned they liked.
Your goal: Rank features by popularity to prioritize development efforts!
๐ Popularity Rules:
- A feature's popularity = number of responses that mention it
- If a user mentions the same feature multiple times in one response, count it only once
- Sort features in descending order by popularity
- If two features have the same popularity, maintain their original order from the features array
Example: If features = ["photoSharing", "videoCall", "chat"] and responses = ["photoSharing videoCall", "videoCall chat chat"], then "videoCall" appears in 2 responses (most popular), while "photoSharing" and "chat" each appear in 1 response. Since "photoSharing" comes before "chat" originally, the result is ["videoCall", "photoSharing", "chat"].
Input & Output
Visualization
Time & Space Complexity
n features ร m responses ร k average words per response. Each feature requires scanning all responses.
Only storing the result list with n tuples, no additional hash maps needed.
Constraints
- 1 โค features.length โค 104
- 1 โค features[i].length โค 10
- features[i] contains only lowercase letters
- 1 โค responses.length โค 103
- 1 โค responses[i].length โค 103
- responses[i] contains only lowercase letters and spaces
- All feature names are unique