Cosine similarity
Implement cosine similarity between two equal-length numeric vectors from scratch. Cosine similarity is the dot product of the two vectors divided by the product of their L2 (Euclidean) norms. Both inputs are non-empty lists of numbers of the same length. If either vector has zero magnitude, return 0.0. Round the result to 6 decimal places.
Implement
cosine_similarity(a: list[float], b: list[float]) → floatExamples
in
[[1,0,0],[1,0,0]]out1What 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,0,0],[1,0,0]]1not run yetsample