Solution to twice coding challenge