a unit tested solution to a interview question