Answer to interview code challenge