Code RoomBinary cross-entropy loss
MediumPrep Room Coding #224

Binary cross-entropy loss

CodingML systemsMid–Senior~20 min

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.

0:00 of about 20 min
InputExpectedGot
[[1,0],[0.9,0.1]]0.105361not run yetsample