Reward Top K Students
Real-world version: Top Reviewers by Note ScoreThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def top_reviewers(positive_feedback: list[str], negative_feedback: list[str], report: list[str], student_id: list[int], k: int) -> list[int]:public List<Integer> topReviewers(String[] positiveFeedback, String[] negativeFeedback, String[] report, int[] studentId, int k)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 13 test cases: 13 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Top K Frequent WordsReal-world version: Most Drawn Part CodesMedium
- High FiveReal-world version: Top Five Average per ApprenticeEasy
- Sort the PeopleReal-world version: Season Leaderboard From Two Parallel ListsEasy
- Make Array Zero by Subtracting Equal AmountsReal-world version: Rounds Needed to Clear Every ReadingEasy