Booking.com Interview Question

I was given a probelm to solve leecode style. then