Headstorm interview question

coding challenge, algorithm