Squarepoint Capital interview question

Medium difficulty programming question from their HackerRank question bank