Pergunta de entrevista da empresa Squarepoint Capital

Hackerrank question is medium difficulty