Adaptiva interview question

The online coding challenge is taken on Hackerrank.