Code Room
CodingEasycod-g1353
Subject Ml metricsLevel Entry–Mid~10 minCommon in ML systems interviewsIndustries Software development

Question

A chatbot routes each user message to one of several intents, numbered 0 to num_classes - 1. The eval dashboard shows, per intent, how many messages the model routed correctly. Given equal-length lists y_true and y_pred of intent ids and the integer num_classes, return a list of length num_classes where position c holds the count of messages with y_true[i] == c and y_pred[i] == c. All ids are valid (between 0 and num_classes - 1). Example: y_true = [0, 1, 2, 1], y_pred = [0, 2, 2, 1], num_classes = 3 gives [1, 1, 1].

Implement
correct_per_class(y_true: list[int], y_pred: list[int], num_classes: int) → list[int]
Examples
in[[0,1,2,1],[0,2,2,1],3]out[1,1,1]
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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.