Two Sigma interview question

A medium leetcode that's on the easier side.