Zillow interview question

Hard Leetcode problem regarding arrays