Dsa
Heap
Hard
Warehouse Inventory Tracker
You manage a warehouse and keep track of incoming products. You need to maintain an inventory of products based on their expiration date, where products have a name, an ID, and an expiration date. Write a function to retrieve the top K products that will expire soonest.
Input Format:
- The first line contains an integer N (the number of products).
- The next N lines each contain a product name, ID, and expiration date (in YYYY-MM-DD format).
- The last line contains an integer K (the number of products to retrieve).
Output Format:
- Print the names of the top K products in the order of their expiration date.
Example Input:
5
Apples 001 2023-10-10
Bananas 002 2023-10-12
Oranges 003 2023-10-11
Grapes 004 2023-10-15
Peaches 005 2023-10-09
3
Example Output:
Peaches
Apples
Oranges
Key concepts
heapinventory_managementsorting
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now