Code Room
CodingMediumcod-g1347
Subject Ml metricsLevel Entry–Mid~16 minCommon in ML systems · Algorithms & data structures interviewsIndustries Software development

Question

Cohen's kappa corrects raw annotator agreement for agreement that would happen by chance. For two equal-length binary label lists a and b of length n, let agree be the count of positions where a[i] == b[i], let pp = (count of 1s in a) * (count of 1s in b), and nn = (count of 0s in a) * (count of 0s in b). Kappa equals (n * agree - (pp + nn)) / (n * n - (pp + nn)). Return the exact integer pair [n * agree - (pp + nn), n * n - (pp + nn)] without dividing. Example: a = [1, 1, 0, 0], b = [1, 0, 0, 0] gives [4, 8].

Implement
kappa_parts(a: list[int], b: list[int]) → list[int]
Examples
in[[1,1,0,0],[1,0,0,0]]out[4,8]
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.