Question
Build bag-of-words count vectors for a set of documents over a fixed vocabulary. Given docs (a list of documents, each a list of word tokens) and vocab (the ordered vocabulary list, assumed to have no duplicates), return for each document a vector of length len(vocab) where position i is the number of times vocab[i] appears in that document. Words not in the vocabulary are ignored. Return the list of count vectors in document order.
bag_of_words(docs: list[list[str]], vocab: list[str]) → list[list[int]][[["a","b","a"],["b","c"]],["a","b","c"]]out[[2,1,0],[0,1,1]]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.