Code RoomCohen kappa numerator denominator
MediumPrep Room Coding #536

Cohen kappa numerator denominator

CodingML systemsAlgorithms & data structuresEntry–Mid~16 min

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.

0:00 of about 16 min
InputExpectedGot
[[1,1,0,0],[1,0,0,0]][4,8]not run yetsample