Doordash phone interview

You need to solve in nlogn

A chef receives all his orders for the day as a list of order ids. Given this list, the chef chooses to prepare them in the following way. He creates a new list by repeatedly removing the smallest eligible order from the list and appending it to the new list. An order is considered eligible if its id is greater than its immediate left and right neighbors in the list. Return the order in which the chef creates the new list. For order id at index 0, it is eligible if it is greater than its right neighbor [Since no left neighbor exists] For order id at index n-1 in a list of size n, it is eligible if it is greater than its left neighbor [Since no right neighbor exists] When there is only one order in the list, it is automatically eligible. Order ids are unique.

Comments (6)