DoorDash interview question

Leetcode hard with a twist.