Two Sigma interview question

leetcode medium question