Donation

If you found the contents in this blog useful, then please make a donation to keep this blog running. You can make donations via Skrill with email address shazin.sadakath@gmail.com

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.


4 comments:

Burke said...

Awesome post, Shazin! The Groovy answer: println "((a-b) + (b-a))"

Burke said...

BTW... congrats on the Amazon.com interview!!!

Cheers,

-Burke

Shahim said...

Really Proud of you. Whatever Allah's plan will happen. Ya at least you got a call from Amazon.com. How many people can say that.

@@ said...

Congratz on the interview! Specially considering that you did not apply in the 1st place! That's a testament to the qork you are capable of! Good luck, may Allah bless you in everything you do.