Booking.com Interview Question

circular dependencies data structure question. we need to show the element from starting to end