Friday, July 14, 2006

Amazon Interview Round 2

The second round was also telephonic. It went for almost 1.5 hours though scheduled for one hour. The main reason for that i think is that i was solving questions and each time i was asked to re-look at the solution I used to improve it further.

Question 1: Shuffle pack of cards
Solution 1: It is one of the most common questions that are being asked in Amazon (Though I came to know this only after the interview:-D). I started with using Sets again but the complexity turned out to be very bad. I assumed that there is a random function with time complexity O(1) and I call this random function to get values from 1...52. Once i get that random function i will add that value in a SET. So in end I will have all the numbers from 1...52 in a random fashion. The catch in my solution was that if the random function returns number x, m times than for each number we will call this function m times and for 52 numbers it will be (m power 52). This is huge. I tried giving another solution but was no better. In the end he moved to next question. Check out here for solution.

Question 2: Count number of lines, characters and words in a file (Given that we don’t have much access to flashy java methods like readline, String methods like indexOf etc.)
Solution 2: The constraint given above simply means that one has to read character by character. I started with a basic program of reading character by character and passing that character to switch statement and doing some logic when ever i got ' ' , '\t', '\n','\r' . But the problem with this solution was that whenever i used to get some odd input like empty file, a file with just '\n' or a file with just a space then i used to patch my earlier solution. Then as i was giving solutions to problems i was asked if I could store some "state". I tokk that lead and provided another solution: -

Store a "state" variable. i.e. when ever a NON- special character (i.e. character apart from ‘ ‘ , ‘\n’ , ‘\r’, ‘\t’ , EOF comes then make the state 0. Whenever a special character comes make state 1. So whenever we go from state 0 to 1. Increase word count. Whenever we get \n or EOF we increase line count. And each time we increase character count.
After this solution no clarification was asked for.

Question 3: Write USE case for Auction model where you have a seller, an item and a buyer.
Solution: This was more generic design question and was just asked to write use-case. Not seq diagram etc.

Learning points 1: Have a nice grip on time complexity. They will make you calculate for each of the solutions you give.
Learning points 2: Concentrate real hard for that 1.5 hours and if you are not clear of the problem then don't hesitate in asking it again.
Learning points 3: You will be asked to write proper code.(even you will be asked to communicate the same through phone)
Learning points 4: The questions will be very generic and never specific to some language.
Learning point 5: Used a variety of test cases to check one's solution before presenting the same to interviewer.

6 comments:

Prateek said...

Good work

Unknown said...

Going to give my second telephonic interview with Amazon today ...hopefully this will help :)

Ankush Bindlish said...

Considering this scenario with some set of assumptions described below. I'd like to provide a brief model design.

Assumptions
1. Multiple sellers have multiple products for multiple buyers.

2. Minimum auction price is maintained for audit history. For instance, Different daterange have different auction price which need to be captured.

3. QuotePrice from a buyer wouldn't be accepted for a particular product from particular seller if there exist a same price for same combination.

4. Product would be sold to one who have maximum quote price within the daterange bid was opened

5. Auction date range would be same as product version date range.

6. At least one buyer would definitely bid for a particular product.

Product_Data :
ProductId
CurrentVersionId

Product :
ProductDataId
ProductId
ProductName
ProductDetails
StartDate
EndDate
AuctionPrice

Seller :
SellerId
SellerName
SellerDetails

Buyer :
BuyerId
BuyerName
BuyerDetails
DepositAmount

Auction :
AuctionId
SellerId
BuyerId
ProductId
QuotePrice
Enabled

Operations
1. CMS of Seller/Buyer/Product.

2. Buyer would add a bid.

3. Buyer can modify his own bid with a larger value. (increasing sequence of quoteprice)

Please note that operation 2 and 3 are possible if and only if (iff) current date falls under the current product version daterange.

4. Seller can disabled the product for auction. Automatic update of product(Enabled) depending on current date can also be provided.

Scope
1. One can add analytics of the product in accordance with buyers.

2. LastUpdatedBy, LastUpdatedDate, VersionNumber can be added to every table.

Please share your comments.

Vineet said...

Hi, Thanks for posting this.It will really help a lot in my Amazon Interviews which are going to scheduled this week

Unknown said...

Hello There,


Your writing shines like gold! There is no room for gibberish here clearly. You nailed it in #topic!



I will have the mp3 files my customer buys on a wordpress page and a cart will direct them to that page. If I want the mp3 files to be downloaded by the customer is there any reason to protect them except to keep them from being indexed by a search engine? Do I need to have a key or do a get operation other than have server-side encryption in S3?


Very useful article, if I run into challenges along the way, I will share them here.


Grazie,
Radhey

Unknown said...

Hi There,


In total awe…. So much respect and gratitude to you folks for pulling off such amazing blogs without missing any points on the Amazon Interview Round 2 . Kudos!


Please help with suspended account. Access to my EC2 and S3 Services has been suspended. I don't know what is the reason. I was writting to support team to restate my account with access to my services few days ago but so far the status is still: unassigned. AWS Training USA





I look forward to see your next updates.


Kind Regards,
Ajeeth