Class Solution

java.lang.Object
g2501_2600.s2512_reward_top_k_students.Solution

public class Solution extends Object
2512 - Reward Top K Students.<p>Medium</p> <p>You are given two string arrays <code>positive_feedback</code> and <code>negative_feedback</code>, containing the words denoting positive and negative feedback, respectively. Note that <strong>no</strong> word is both positive and negative.</p> <p>Initially every student has <code>0</code> points. Each positive word in a feedback report <strong>increases</strong> the points of a student by <code>3</code>, whereas each negative word <strong>decreases</strong> the points by <code>1</code>.</p> <p>You are given <code>n</code> feedback reports, represented by a <strong>0-indexed</strong> string array <code>report</code> and a <strong>0-indexed</strong> integer array <code>student_id</code>, where <code>student_id[i]</code> represents the ID of the student who has received the feedback report <code>report[i]</code>. The ID of each student is <strong>unique</strong>.</p> <p>Given an integer <code>k</code>, return <em>the top</em> <code>k</code> <em>students after ranking them in <strong>non-increasing</strong> order by their points</em>. In case more than one student has the same points, the one with the lower ID ranks higher.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> positive_feedback = [&ldquo;smart&rdquo;,&ldquo;brilliant&rdquo;,&ldquo;studious&rdquo;], negative_feedback = [&ldquo;not&rdquo;], report = [&ldquo;this student is studious&rdquo;,&ldquo;the student is smart&rdquo;], student_id = [1,2], k = 2</p> <p><strong>Output:</strong> [1,2]</p> <p><strong>Explanation:</strong> Both the students have 1 positive feedback and 3 points but since student 1 has a lower ID he ranks higher.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> positive_feedback = [&ldquo;smart&rdquo;,&ldquo;brilliant&rdquo;,&ldquo;studious&rdquo;], negative_feedback = [&ldquo;not&rdquo;], report = [&ldquo;this student is not studious&rdquo;,&ldquo;the student is smart&rdquo;], student_id = [1,2], k = 2</p> <p><strong>Output:</strong> [2,1]</p> <p><strong>Explanation:</strong></p> <ul> <li> <p>The student with ID 1 has 1 positive feedback and 1 negative feedback, so he has 3-1=2 points.</p> </li> <li> <p>The student with ID 2 has 1 positive feedback, so he has 3 points. Since student 2 has more points, [2,1] is returned.</p> </li> </ul> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= positive_feedback.length, negative_feedback.length <= 10<sup>4</sup></code></li> <li><code>1 <= positive_feedback[i].length, negative_feedback[j].length <= 100</code></li> <li>Both <code>positive_feedback[i]</code> and <code>negative_feedback[j]</code> consists of lowercase English letters.</li> <li>No word is present in both <code>positive_feedback</code> and <code>negative_feedback</code>.</li> <li><code>n == report.length == student_id.length</code></li> <li><code>1 <= n <= 10<sup>4</sup></code></li> <li><code>report[i]</code> consists of lowercase English letters and spaces <code>' '</code>.</li> <li>There is a single space between consecutive words of <code>report[i]</code>.</li> <li><code>1 <= report[i].length <= 100</code></li> <li><code>1 <= student_id[i] <= 10<sup>9</sup></code></li> <li>All the values of <code>student_id[i]</code> are <strong>unique</strong>.</li> <li><code>1 <= k <= n</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • topStudents

      public List<Integer> topStudents(String[] positiveFeedback, String[] negativeFeedback, String[] report, int[] studentId, int k)