Code Room
CodingEasycod-g1063
Subject Ml metricsLevel Mid~15 minCommon in ML systems interviewsIndustries Software development

Question

Given two lists of items (which may contain duplicates), compute the Jaccard similarity and the Dice (Sorensen) coefficient of their distinct-element sets. Jaccard = |A intersect B| / |A union B|, and Dice = 2*|A intersect B| / (|A| + |B|), where A and B are the sets of distinct items. If both sets are empty (union empty), define both similarities as 1.0. Return [jaccard, dice], each rounded to 4 decimals.

Implement
jaccard_dice(a: list, b: list) → list[float]
Examples
in[[1,2,3],[2,3,4]]out[0.5,0.6667]
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.