Squarepoint Capital interview question

Hackerrank question is medium difficulty