Advertisement

Sri Lanka's First and Only Platform for Luxury Houses and Apartment for Sale, Rent

Thursday, August 30, 2012

Amazon.com Interview!!!! Yeah you heard it, Amazon.com! - 3

Thanks to almighty god, I was contacted by Kristin on Friday (24/08/2012) and invited for the 3rd interview which was held on today (30/08/2012).

A Software Development Engineer named Armin contacted me and as usual he asked some general questions followed by technical questions.One of the main questions was;

Given integer array and number k find the two numbers in the array which will add up and become equal to k

The solution I wrote was as below.

int [] inA = new int[6]{1,2,3,4,5,6};
int k = 2

 int[] find ( int[] inArray, int k ) {
     int n1, n2;
     outer:
     for(int i=0;i<inArray.length;i++) {
         for(int j=0;j<inArray.length;j++) {
             if((inArray[i] + inArray[j]) == k && i != j) {
                 n1 = inArray[i];
                 n2 = inArray[j];
                 break outer;
             }
         }
     }
     
     if(n1 == 0 && n2 == 0) {
         return null;
     }
     
     return new int[] { n1, n2 };
 }
The complexity is O(n^2) and Armin was ok with it. Then he asked me whether I have any questions and I asked about my prospective line of work there. He said it will be mostly Payment Transaction processing related development. Anyhow I am thankful to god for giving me this entire experience.

Wednesday, August 22, 2012

Amazon.com Interview!!!! Yeah you heard it, Amazon.com! - 2

Thanks to all mighty god. I got through the first phone interview and was emailed on 17/08/2012 by Kristin to schedule a second phone interview. Usually Amazon has 3 phone interviews prior to an onsite interview. I fixed the next interview to be on Yesterday (21/08/2012) at 9.00 a.m. PT which is 9.30 p.m. local time.

A Software Development Engineer named Pascal Schoenhardt phoned me and he asked some General Questions first. Followed by a technical question which was;

How to traverse a binary tree level by level.

my answer was in Pseudo Code

Function traverse(Node n)
       list.add(n)
       
       while(list not empty) 
           Node n = list.get()
           Print n.value
           
           if(n.leftChild not null)
               list.add(n.leftChild)
           if(n.rightChild not null)
               list.add(n.rightChild)

He seemed ok with the answer. Then he asked me whether I had any questions and I asked about the work environment at Amazon. He explained alot and it seems like a fun place to work in. Then he gave me a Take Home question and asked me to reply to his Email Address the Solution. The problem was


Given:

A log from a website, where each line is a 2-or-3 element CSV sequence containing:
SessionID,Page URL,[Optional Error Code]
The error code field will be populated if an error occurred while the page was loading.
    
Problem:

Parse the log, and produce a list of three page sequences in which lead to an error, 
sorted by occurrance (highest first). That is, every time an error occurs, if the 
sessions in which it occurred has at least two previous successful page loads, we 
have a new three page sequence leading to an error. We are only interested in three 
page sequences. The customer may continue to browse after encountering an error.

Assumptions:

- You have a function getNextLogLine() which returns a CSV string, or null if the end of the log is reached.
- You may assume that you have all of the standard data structures available to you in library form.

Example:

Log File
    123,/products/a.html
    456,/products/a.html
    789,/products/d.html
    789,/products/a.html
    123,/products/b.html
    789,/products/c.html
    456,/products/b.html
    789,/products/d.html,Err2
    123,/products/c.html,Err1
    456,/products/c.html,Err1

Sample Output:            (3 page sequence)                (err)  (count)
    {/products/a.html, /products/b.html, /products/c.html}, Err1, 2
    {/products/a.html, /products/c.html, /products/d.html}, Err2, 1


I was staying awake and wrote the solution and mailed him back with the answer. The interview was a great experience and as always I am thankful to god for giving me this opportunity.


Thursday, August 16, 2012

Amazon.com Interview!!!! Yeah you heard it, Amazon.com!

What a night? All praise to god for giving me this opportunity. I was contacted by a Amazon.com recruiting coordinator named Kristin last week explaining that their Recruiting Manager has apparently seen my CV on monster.com and really interested to have a phone interview with me. I was over the moon! but to my horror I didn't see a reply up until last Tuesday but then Kristin finally contacted me and fixed a date for a phone interview. I decided the date to be Thursday 9.00 a.m. PT.

A Software Development Engineer named Yanlin phoned me and we had the interview for approximately one hour. The guy is really nice and asked me general as well as technical questions. One of the major coding questions was the following

Given two arrays of numbers of same size.  For elements in one array, assume that you can always find a matching element in the other array, except for one element.  So what you got is two elements that differ from each other and all rest should match in the two arrays.  Write a function to print out these two numbers.

My solution which I wrote within 15 minutes is as follows. Not the ideal or most efficient one but it works ;).


public static void findNonMatching(int[] a, int[] b) {
    if(a.length != b.length) {
        return;  // Yan - given the question requirement, validation check.
    }
    
     // Yan - optimize when
     for(int i=0;i<a.length;i++) {
         boolean foundEqualA = false;
         boolean foundEqualB = false;
         inner1:
         for(int j=0;j<b.length;j++) {
             if(a[i] == b[j]) {
                 foundEqualA = true;
                 break inner1;
             }
         }
         inner2:
         for(int j=0;j<b.length;j++) {
             if(b[i] == a[j]) {
                 foundEqualB = true;
                 break inner2;
             }
         }
         if(!foundEqualA) {
             System.out.println("In A " +a[i]);             
         }
         if(!foundEqualB) {
             System.out.println("In B " +b[i]);
         }
     }

}

The complexity is O(n^2). You can see comments by Yanlin himself.Anyway I am quite happy and thankful to god for giving me this opportunity. As the famous saying says "Experience is what you get, When you didn't get what you want". Even if I don't get this the experience will be there for a life time.