Tap here to switch tabs
Problem
Submissions

Problem: Sort Features by Popularity

Try to solve the Sort Features by Popularity problem.

Statement

You are given an array of unique strings features and an array of strings responses. Each element in responses is a string consisting of space separated words.

The popularity of a feature is defined as the total number of responses in responses that contain the feature as an individual word at least once.

Sort the features array in descending order based on each feature’s popularity. If multiple features have the same popularity, maintain their original relative order from features.

Return the sorted features array.

Constraints:

  • 1≤1 \leq features.length ≤104\leq 10^4

  • 1≤1 \leq features[i].length ≤10\leq 10

  • features contains no duplicates.

  • features[i] consists of lowercase English letters.

  • 1≤1 \leq responses.length ≤102\leq 10^2

  • 1≤1 \leq responses[i].length ≤103\leq 10^3

  • responses[i] consists of lowercase English letters and spaces.

  • responses[i] contains no two consecutive spaces.

  • responses[i] has no leading or trailing spaces.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Sort Features by Popularity

Try to solve the Sort Features by Popularity problem.

Statement

You are given an array of unique strings features and an array of strings responses. Each element in responses is a string consisting of space separated words.

The popularity of a feature is defined as the total number of responses in responses that contain the feature as an individual word at least once.

Sort the features array in descending order based on each feature’s popularity. If multiple features have the same popularity, maintain their original relative order from features.

Return the sorted features array.

Constraints:

  • 1≤1 \leq features.length ≤104\leq 10^4

  • 1≤1 \leq features[i].length ≤10\leq 10

  • features contains no duplicates.

  • features[i] consists of lowercase English letters.

  • 1≤1 \leq responses.length ≤102\leq 10^2

  • 1≤1 \leq responses[i].length ≤103\leq 10^3

  • responses[i] consists of lowercase English letters and spaces.

  • responses[i] contains no two consecutive spaces.

  • responses[i] has no leading or trailing spaces.