All problems
0830MediumArrayHash TableStringSortingHeap (Priority Queue)

Top Reviewers by Note Score

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2512Reward Top K Students

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A workshop scores its reviewers on the notes they leave. positive_feedback lists the words counted as praise and negative_feedback lists the words counted as criticism. No word appears in both lists.

report[i] is the note left by the reviewer whose badge number is student_id[i]. A note is lowercase words separated by single spaces. Scoring a note starts at zero, adds 3 for each word of the note that appears in the praise list, and subtracts 1 for each word that appears in the criticism list. A word only counts when it matches a listed word exactly; a listed word appearing inside a longer word does not count. A word counts once for each time it appears in the note.

Rank the reviewers by score, highest first, and settle a tie in favour of the smaller badge number. Return the badge numbers of the top k reviewers, in that ranked order.

Examples

Example 1

Input
positive_feedback = ["neat", "sharp"], negative_feedback = ["messy", "late"], report = ["neat work sharp finish", "messy and late", "plain work"], student_id = [42, 7, 19], k = 2
Output
[42, 19]

Badge 42 leaves two praise words for a score of 6. Badge 19 leaves none of either, scoring 0. Badge 7 leaves two criticism words, scoring -2. The top two in that order are 42 then 19.

Example 2

Input
positive_feedback = ["neat"], negative_feedback = ["messy"], report = ["neat", "neat"], student_id = [9, 4], k = 2
Output
[4, 9]

Both reviewers score 3. The tie is settled in favour of the smaller badge number, so badge 4 is ranked ahead of badge 9.

Example 3

Input
positive_feedback = ["neat"], negative_feedback = ["messy"], report = ["neatly done", "neat"], student_id = [3, 8], k = 2
Output
[8, 3]

The word "neatly" is not the listed word "neat", so badge 3 scores 0 while badge 8 scores 3.

Constraints

  • 1 <= positive_feedback.length <= 10^4
  • 1 <= negative_feedback.length <= 10^4
  • 1 <= positive_feedback[i].length <= 100
  • 1 <= negative_feedback[i].length <= 100
  • No word appears in both positive_feedback and negative_feedback
  • 1 <= report.length <= 10^4
  • report.length == student_id.length
  • 1 <= report[i].length <= 100
  • report[i] is lowercase words separated by single spaces
  • 1 <= student_id[i] <= 10^9
  • All badge numbers are distinct
  • 1 <= k <= 10^4
  • k <= report.length

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def top_reviewers(positive_feedback: list[str], negative_feedback: list[str], report: list[str], student_id: list[int], k: int) -> list[int]:
Java
public List<Integer> topReviewers(String[] positiveFeedback, String[] negativeFeedback, String[] report, int[] studentId, int k)
September 7
Apply