Zillow interview question

It was a leetcode hard