Code Room
Code reviewHardcr-g268
Subject Boundary conditionsLevel Mid–Senior~18 minCommon in Concurrency interviewsIndustries Software development

Question

Review this Go code that removes expired sessions from a map while iterating.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.

Talk through your review
Code to reviewgo
func reap(sessions map[string]Session, now time.Time) int {    removed := 0    for id, s := range sessions {        if s.expiresAt.Before(now) {            delete(sessions, id)            removed++        }        if s.lastSeen.Add(idleTTL).Before(now) {            sessions[id] = touch(s)   // refresh non-expired idle ones        }    }    return removed}
Run or narrate your approach, then ask the coach.