#24 solution without wrapping