1772. Sort Features by Popularity
https://leetcode.com/problems/sort-features-by-popularity
Description
You are given a string array features
where features[i]
is a single word that represents the name of a feature of the latest product you are working on. You have made a survey where users have reported which features they like. You are given a string array responses
, where each responses[i]
is a string containing space-separated words.
The popularity of a feature is the number of responses[i]
that contain the feature. You want to sort the features in non-increasing order by their popularity. If two features have the same popularity, order them by their original index in features
. Notice that one response could contain the same feature multiple times; this feature is only counted once in its popularity.
Return the features in sorted order.
Example 1:
Example 2:
Constraints:
1 <= features.length <= 104
1 <= features[i].length <= 10
features
contains no duplicates.features[i]
consists of lowercase letters.1 <= responses.length <= 102
1 <= responses[i].length <= 103
responses[i]
consists of lowercase letters and spaces.responses[i]
contains no two consecutive spaces.responses[i]
has no leading or trailing spaces.
ac
Last updated