How to proceed with the problem


I am struck on this any help will be welcome.

Hi @Krishna-Singh-2678805765519156

This problem can be solved using a greedy approach.

We have to remember that Tieu cannot know about future orders beforehand. So he will have to serve one of the orders that are currently waiting to be served. This is where the greedy approach comes. He should always serve the order which has minimum cooking time i.e. the order with the minimum L .

which ds to use?how to implement/

At first, we need to sort the orders according to increasing order time. An array is sufficient here. But then we need to store the currently available orders according to increasing cooking time. We can use a min heap for this purpose. We will loop through the array. Upon arriving at the i th order, we will insert it into the min heap if its order time is less than or equal to the current time. Otherwise, we will keep serving from the top of the heap until current time becomes larger than or equal to the order time of the i th order or the heap becomes empty. We will update the current time while inserting an order into the heap ( if needed ) and also while serving an order.

Here is the code for better understanding :

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.