DoorDash interview question

Two leetcode medium to hards.