The Reward Top K Students interview question gives you a list of positive and negative feedback words, and a list of student reports (each report is a list of words). Each positive word in a report earns 3 points, each negative word costs 1 point. You must return the IDs of the top k students sorted by score (descending), with ties broken by student ID (ascending).
Booking.com asks this problem because it combines hash table lookup, score computation, and priority queue or sorting — all common in recommendation systems, content moderation, and student/employee ranking platforms. It tests whether candidates can efficiently score items using a lookup set and then sort by a composite key.
The pattern is hash set lookup combined with sorting or heap. Build sets for positive and negative words for O(1) lookup. For each student report, scan each word: if in positive set, add 3 to score; if in negative set, subtract 1. Store (-score, student_id) tuples for sorting (negative score for descending order, student_id for ascending tiebreak). Sort the tuples and return the first k student IDs. Alternatively, use a heap of size k.
Positive words: {"smart", "brilliant"}. Negative words: {"lazy", "bad"}.
Reports:
["smart", "work", "lazy"] → 3 - 1 = 2.["brilliant", "bad"] → 3 - 1 = 2.["brilliant", "smart"] → 3 + 3 = 6.Scores: [(2, 0), (2, 1), (6, 2)]. Sort by (-score, id): [(6,2), (2,0), (2,1)].
Top 2: [2, 0].
For the Reward Top K Students coding problem, the hash table, sorting, and heap interview pattern is the efficient path. Using sorted(scores, key=lambda x: (-x[0], x[1])) in Python naturally handles the composite sort key. Booking.com interviewers appreciate candidates who mention that the heap approach (using heapq.nsmallest with the same tuple key) is more efficient when k << n. Practice expressing composite sort keys cleanly.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Most Popular Video Creator | Medium | Solve | |
| Alert Using Same Key-Card Three or More Times in a One Hour Period | Medium | Solve | |
| Before and After Puzzle | Medium | Solve | |
| Find And Replace in String | Medium | Solve | |
| Group Anagrams | Medium | Solve |