Amazon Interview Question for Software Engineer / Developers






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

I was asked similar question and I failed to solve this

Clone a link list in which every node has two pointers: one pointer points to next node, and the other pointer points to some random node in the same list.

Solution:
step1:for every node, clone a node and add it to the list as the next node;
step2:for each odd-number node, change the ref pointer to the next node of the node it points ti
step3: split even-number nodes and odd-number nodes into two lists. The list which contains the odd-number nodes is the clone of the original list.

- ggtt February 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Simple solution
Create a hashmap of Original address of node and corresponding cloned node's address.
After the clone list is ready, use the reference pointer as the key to hashmap. The value is the address of the node in cloned list.

- Saurabh Shah February 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

not very clear about the question. explicitly set it to NULL or point to the same object as the original one?

- Anonymous January 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

They can be any two pointers to other nodes..The only thing we have to be careful while copying the pointers is that we could have visited a previously visited node.so we need to have something like a hash map.

- Musheka January 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can you clarify this question?

- Phoenix February 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

What does the *reference struct member do ?

- Phoenix February 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

reference is a pointer of type struct node, same as next !!!

- Samana Srikanth March 19, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

reference pointer point to a arbitary node in the same linklist (i.e) a reference pointer in 2nd node can point to 7th node of the same list.
Now if we have to clone this list, while cloning second node you will now have to point the reference pointer to 7th node which is still not created as you are still in process of cloing 2nd node.
Now the question is how do you fill up all reference nodes with address that are not created, and also if some 4th node reference points to 2nd node, you still need to know that it points to 2nd node to fill this reference.

I hope this clarifies the quesiton.

- blrbuddy March 25, 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