Airbnb interview question

Variant of a Leetcode hard problem