Crossover for Work interview question

Leetcode style, medium difficulty question.