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

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.

Implement
term_frequency(doc: str) → list[list]
Examples
in["the cat the dog"]out[["cat",0.25],["dog",0.25],["the",0.5]]
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.