Code Room
Vibe codingHardvc-g043
Subject Ai code reviewLevel Senior–Staff~20 minCommon in Concurrency interviewsIndustries Software development, Technology

Question

You asked an AI assistant for a concurrent word-count over a list of documents in Go, combining results into one map. It produced:

go
func countWords(docs []string) map[string]int {    counts := make(map[string]int)    var wg sync.WaitGroup    for _, doc := range docs {        wg.Add(1)        go func(d string) {            defer wg.Done()            for _, w := range strings.Fields(d) {                counts[w]++            }        }(d := doc)    }    wg.Wait()    return counts}

(Assume the closure capture is fixed to the obvious form.) It returns plausible counts in a small run. What's the defect?

What a strong answer looks like

Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it — tests, edge cases, reading critically — and how you’d re-prompt or decompose to get it right.

Describe your solution

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.