Squarepoint Capital interview question

Leetcode style coding exercise. Difficulty: easy/medium