Amazon Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

What do you mean L1 look same as L2,please clarify your question first.

- Derek November 02, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what a stupid.... he couldn't even explain the question... leave abt answer...!!!!

- vinaysachdeva23 November 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

What the hell...atleast clarify the question dude

- dabangg November 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Although I agree with everyone that 'omkar' should word the question more clearly, it is almost easy to guess that he meant the following:

"Minimum no. of changes required to change L1 to L2 in terms of having nodes in same order with same data, with possible changes allowed as adding, deleting, swapping nodes".

Input [consider a toy example]:
L1 - 12->13->45->1->33->NULL
L2 - 13->12->0->45->NULL

Result:
1. Swap Node 12 and Node 13 in L1.
2. Delete Node 1 and Node 33 in L1.
3. Add Node 0 in L1.

This would be similar to the Edit Distance problem with strings. If allowed, we could simply store the data values as a string and try to find the minimum edit distance.


Nice question BTW!

- gradStudent November 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

en.wikipedia.org/wiki/Levenshtein_distance using this algorithm we can do it in O(n2)

- sachin323 November 04, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

why would you compute edit-distance and all that as the problem here is to simply convert L2 to L1?

instead of adding/removing/swapping and all that, plainly set the values of nodes in L2 till the length of L1 (deleting if L1 is shorter, inserting if greater)... you can avoid the time involved in performing checks with IF in cases where the target value to be assigned is the same as the one stored already (not sure if setting the value will be more expensive than doing a control switch for IF)...

- svix December 15, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@gradStudent - L1 and L2 are sorted

- swethasivas November 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@gradStudent - L1 and L2 are sorted

- swethasivas November 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

My answer would be to reverse l1 and l2 pointers!!!! Kaam khatam :)

- anonymous February 05, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

minimum edit distance is the test point I think.

- weijiang2009 February 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How if we do this?

create an array of m* n elements ( m= num of elements of list l1) , n= number of elements of list l2.
then , place the difference of distances in the matrix Di,j
Now just check the difference and place in the distance matrix.
Also, after the step , just check the minimum distance Mini,j and get the corresponding value of i for that value of j.
thus we get the node corresponding to the similar node in the list.
That would work right???

- Anonymous August 08, 2011 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More