Machine Coding Round
Questions: The problem involves creating an Online Auction System for a company FooBar where users can participate in auctions. The system must handle the following functionalities:
- Add Buyer(name)
- Add Seller(name)
- Create Auction(id, lowest bid limit, highest bid limit, participation_cost, seller)
- Create/Update Bid(buyer, auction, amount)
- Withdraw bid(buyer, auction)
- Close auction and return winning bid
- Get profit/loss(seller, auction)
Highest Unique Bid Definition: For example, if users A, B, C, D, E, F participate in auction A1 with the following bids:
- A bids 50
- B bids 90
- C bids 100
- D bids 90
- E bids 70
- F bids 100
Here, 70 is the highest unique bid, making E the winner. If no unique highest bid exists, there is no winner.
Sample Test Cases: Test case 1:
- ADD_BUYER("buyer1")
- ADD_BUYER("buyer2")
- ADD_BUYER("buyer3")
- ADD_SELLER("seller1")
- CREATE_AUCTION("A1", "10", "50", "1", "seller1")
- CREATE_BID("buyer1", "A1", "17")
- CREATE_BID("buyer2", "A1", "15")
- UPDATE_BID("buyer2", "A1", "19")
- CREATE_BID("buyer3", "A1", "19")
- CLOSE_AUCTION("A1") // Should give Buyer1 as winner
- GET_PROFIT("seller1", "A1") // (17 + (3 * 0.2 * 1) - 30) = -12.4
Test case 2:
- ADD_SELLER("seller2")
- CREATE_AUCTION("A2", "5", "20", "2", "seller2")
- CREATE_BID("buyer3", "A2", 25) // This should fail as highest bid limit is 20 for A2
- CREATE_BID("buyer2", "A2", 5)
- WITHDRAW_BID("buyer2", "A2")
- CLOSE_AUCTION("A2") // No winner
- GET_PROFIT("seller2", "A2") // (1 * 0.2 * 2) = 0.4 only consider profit from participation cost
Candidate's Approach
The candidate designed a class structure to represent Buyers, Sellers, and Auctions. Each auction maintains a list of bids, and the system checks for the highest unique bid when closing an auction. The profit/loss calculation for sellers is implemented based on the provided formula. The candidate ensured that the code is modular and adheres to object-oriented principles, allowing for easy extension and maintenance.
Interviewer's Feedback
The interviewer appreciated the candidate's approach to modular design and the clear implementation of functionalities. However, they suggested adding more edge case handling, especially for bid limits and auction closures. The interviewer also recommended improving the documentation within the code for better clarity.