Booking.com Interview Question

2 pointers array problem O(n)