Pergunta de entrevista da empresa InRhythm

Codility challenge question. Involved coding task.