Jaccard and Dice similarity
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.
0:00 of about 15 min
solution.py
InputExpectedGot
[[1,2,3],[2,3,4]][0.5,0.6667]not run yetsample