Amazon Interview Question
Software Engineer / DevelopersA mediator design pattern could be used here. 'AuctionSystem' class (and interface) could be the Mediator and 'Bidders' class (and interface) could be the colleagues.
1. AuctionSystem member functions -
MaintainProductList() //Basically an ArrayList or a hashMap with key as product Id and values as current bidders
AddBidders() //Add bidders to the productList bidding in a sorted order (to ease the query of topBidder) . Could use MaxHeap as well.
RemoveBidder(Bidder ID) // Remove and reheapify
UpdateBidder(Bidder ID, Long newValue) //To update the bidding value and re-organizing.
PublishBidResult(Product Id).
Optimisitc approach, all other operations can store the bidding values unsorted and whenever PublishBidResults() is called, heapify can be done to publish the top value.
2. Bidder class member functions could have
- makeBid( int Product Id, Long Value)
- Long getCurrentBidValue (int ProductId)
<pre lang="" line="1" title="CodeMonkey55969" class="run-this">/* The class name doesn't have to be Main, as long as the class is not public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
java.io.BufferedReader r = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
String s;
while (!(s=r.readLine()).startsWith("42")) System.out.println(s);
}
}
</pre><pre title="CodeMonkey55969" input="yes">
123</pre>
Main Class AuctionSystem it copntains
- WgpShashank April 29, 2011constructor
AuctionSystem()
AuctionSystem(bidowner,product)
AuctionSystem(bidowner)
AuctionSystem(product)
AddBid Owner ArrayList
remove bidOwner
Class BidOwner
addproduct(name,type etc) //add bid
remove product //withdraw bid
void go_for_Auction(bidowner,product) or place_bid()
setMinPrize(product)
setQuantity(product)
setwinner(user)
setTimelimit(no of days)
class users //Bidders//2rd party user who wants to buy the item using bid
{
users()
setbidprize(product)//update
remove bidprize(product) //withdraw from bid
addreview(product)
seeproductinfo(product)
seeBidOwnerInfo(BidOwner)
}
Desighn pattern & Interection between them Needed