Description
Company: Jane Street
Task Description
Implement a trading system with the ability to fulfill buy orders and support order cancellation and rollback.
Requirements
Class Item:
buyer: String (optional/nullable)seller: Stringprice: Integeritem_name: String
Class Database:
show_all_items(): Output all items in the market.
Trading Logic:
buy(item_name, buyer_name, max_price): Logic to sell items in the market starting with the cheapest available (that is<= max_price).cancel_order(buyer_name): Cancel all orders from a specific buyer.- Rollback: This must "roll back" the records, making the items available for sale again.
- Reprocessing: Handle the case where another buyer previously missed out on an item because this buyer took it. Ensure transactions are reprocessed or the state allows others to buy the freed items.
Data Scale
- Support up to 1000 items and users.
Test Cases
- Add three items to the market and display their information.
- Simulate buyers purchasing items at different prices and validate updates.
- Simulate order cancellation and rollback, verifying that items become available or are taken by waitlisted buyers (if queueing is implemented).
Discussion (0)
All comments are anonymous. Your identity is not shared.
Loading comments...
Loading editor…
OUTPUTLast run results appear here.
No output yet. Click "Run Code" to see results.