My solution to an interview question I faced recently.