Medium questions combine two or three steps, and most hide one trap: a tie, a missing value, a group that should restart, or an average of averages. Say the trap out loud before you write the code; interviewers listen for it.
Work from the shape of the answer backwards: one number, a name, a short table. Then check the result against the data in the console before you call it done.