#2512
Reward Top K Students
specialist · 935 · lc medium +32 · verified · 46.9% accepted · 363 likes · top 31%
Description
Given word lists positive_feedback and negative_feedback (no word appears in both), and n feedback reports with their associated student_id values, score each student starting from 0: each positive word in their report adds 3 points and each negative word subtracts 1. Return the IDs of the top k students ranked by score descending (ties broken by lower ID first).
Example 1:
Input: positive_feedback = ["smart","brilliant","studious"], negative_feedback = ["not"], report = ["this student is studious","the student is smart"], student_id = [1,2], k = 2
Output: [1,2]
Explanation:
Both the students have 1 positive feedback and 3 points but since student 1 has a lower ID he ranks higher.
Example 2:
Input: positive_feedback = ["smart","brilliant","studious"], negative_feedback = ["not"], report = ["this student is not studious","the student is smart"], student_id = [1,2], k = 2
Output: [2,1]
Explanation:
- The student with ID 1 has 1 positive feedback and 1 negative feedback, so he has 3-1=2 points.
- The student with ID 2 has 1 positive feedback, so he has 3 points.
Since student 2 has more points, [2,1] is returned.
Code
1
2
3