Code Room
CodingMediumcod-g1060
Subject Machine learningLevel Mid–Senior~20 minCommon in ML systems interviewsIndustries Software development, Technology

Question

Compute the binary cross-entropy (log loss) of a classifier. Given y_true (labels 0/1) and y_prob (predicted probabilities of the positive class, each in [0,1]), the log loss is the negative mean over samples of y*ln(p) + (1-y)*ln(1-p). To avoid log(0), clip every probability into the range [eps, 1-eps] with eps = 1e-15 before taking logs. Return the mean log loss rounded to 6 decimal places. The lists are non-empty and equal length, up to 10^5 elements.

Implement
log_loss(y_true: list[int], y_prob: list[float]) → float
Examples
in[[1,0],[0.9,0.1]]out0.105361
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.