Code Room
CodingEasycod-g982
Subject Machine learningLevel Entry–Mid~18 minCommon in ML systems interviewsIndustries Software development

Question

One-hot encode a list of categorical string labels. First build the sorted list of unique categories. Then return a list of one-hot row vectors (lists of 0/1 ints), one per input label, where each row has a 1 in the column corresponding to that label's position in the sorted unique-category list and 0 elsewhere. The input list is non-empty.

Implement
one_hot_encode(labels: list[str]) → list[list[int]]
Examples
in[["cat","dog","cat"]]out[[1,0],[0,1],[1,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.