Question
Compute term frequencies for a tiny document. Given a document string, lowercase it and split on whitespace into tokens, then return a list of [term, frequency] pairs where frequency is the count of that term divided by the total number of tokens. Include each distinct term once, ordered alphabetically by term. If the document is empty or all-whitespace (zero tokens), return an empty list. Round each frequency to 4 decimal places.
term_frequency(doc: str) → list[list]["the cat the dog"]out[["cat",0.25],["dog",0.25],["the",0.5]]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.