ING interview question

Codility easy to medium