Back to problems

Implement a Level-Aware Expiring Inventory Store

Object-Oriented Programming · Optiver · Medium

Heap per Level with Lazy Expiration Keep one max heap per level so the best item on a level can be fetched quickly. Python's heapq is a min heap, so each entry is stored as a triple of negative weight, negative store timestamp, and item id. This makes the heap top equivalent to the highest weight, with ties resolved by the most recent store timestamp. The active/expired state is tracked separately in a dictionary of item records. A global expiration min heap lists active…

Checking your access…