Code Room
CodingEasycod-g974
Subject Machine learningLevel Entry–Mid~15 minCommon in ML systems interviewsIndustries Software development, Technology

Question

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]) → float
Examples
in[[1,0,0],[1,0,0]]out1
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.