Booking.com interview question

2 pointers array problem O(n)