Code Room
CodingMediumcod-g1070
Subject Machine learningLevel Mid–Senior~25 minCommon in ML systems interviewsIndustries Software development

Question

Perform one epoch of perceptron training. Given weights (a list of d floats), bias (a float), X (a list of samples, each a list of d floats), y (labels, each +1 or -1), and learning_rate, process the samples in order. For each sample, compute activation = dot(weights, x) + bias; the prediction is +1 if activation >= 0 else -1. On a misclassification (prediction != label), update weights[j] += learning_rate * label * x[j] for all j and bias += learning_rate * label. Return [updated_weights, updated_bias], with every number rounded to 6 decimals. There is at least one sample and d >= 1.

Implement
perceptron_epoch(weights: list[float], bias: float, X: list[list[float]], y: list[int], learning_rate: float) → list
Examples
in[[0,0],0,[[1,1]],[1],1]out[[0,0],0]
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.