Code RoomTop-k violations count
EasyPrep Room Coding #547

Top-k violations count

CodingML systemsEntry–Mid~10 min

A moderation model ranks the day's flagged posts from most to least suspicious, and human reviewers only get through the first k. To judge whether the top of the queue is worth their time, count the real violations there. Given ranked_labels, a list ordered by the model's ranking where 1 means the post truly violated policy and 0 means it did not, and an integer k >= 0, return the number of 1s among the first k entries. If k exceeds the list length, use the whole list. Example: ranked_labels = [1, 0, 1, 1, 0], k = 3 returns 2.

Implement
hits_in_review_budget(ranked_labels: list[int], k: int) → int
Examples
in[[1,0,1,1,0],3]out2
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 10 min
InputExpectedGot
[[1,0,1,1,0],3]2not run yetsample