Ctrl K

Intern Leaderboard From Reviews

Medium
Mentors write short reviews of their interns. There is a list of praise words praise and a list of critical words critique; no word appears in both. Review reviews[i] is about the intern with ID ids[i], and every intern has exactly one review. Each word of a review found in praise gives the intern +3 points, each word found in critique takes away 1 point, and any other word changes nothing. A repeated word counts every time it appears. Rank the interns by points from highest to lowest, breaking ties by the smaller ID first. Return the IDs of the first k interns in that order.
Example 1
praise=['neat', 'fast'], critique=['late', 'sloppy'], reviews=['neat and fast work', 'late again', 'fast but sloppy'], ids=[7, 3, 5], k=2 → [7, 5]

Intern 7 gets two words of praise: 3 + 3 = 6 points. Intern 3 gets one critical word: -1. Intern 5 gets one of each: 3 - 1 = 2. The top two are 7 and 5.

Example 2
praise=['kind'], critique=['rude'], reviews=['kind', 'kind'], ids=[9, 4], k=1 → [4]

Both have 3 points; on a tie the smaller ID ranks higher, so it is 4.

Example 3
praise=['clear'], critique=['vague'], reviews=['vague and vague again', 'nothing special'], ids=[12, 30], k=2 → [30, 12]

A word that appears twice counts twice: intern 12 ends with -2 and intern 30 with 0, so 30 comes first.

Constraints
  • 1 ≤ len(praise), len(critique) ≤ 10⁴
  • words in praise and critique are 1–100 lowercase English letters, and the lists share no word
  • 1 ≤ len(reviews) = len(ids) ≤ 10⁴
  • reviews[i] is 1–100 characters: lowercase English letters with single spaces between words
  • 1 ≤ ids[i] ≤ 10⁹, all IDs are distinct
  • 1 ≤ k ≤ len(reviews)
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsMost Searched Words MediumTop Channel's Best Clip MediumAnagram Buckets MediumMost Common Values MediumCharacters Grouped by Count Medium
loading Python…
Input
praise=['neat', 'fast'], critique=['late', 'sloppy'], reviews=['neat and fast work', 'late again', 'fast but sloppy'], ids=[7, 3, 5], k=2
Expected
[7, 5]

Run checks the first 3 tests in your browser. Submit checks all 84 tests on the server, hidden ones included.