Amazon Interview Question for Software Engineer / Developers






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

isnt the first one a subset sum variation with constraint of size = 3? Its not the first 3 indices rite? its just the 3 indices whose sum is k?

for the copy of linked list...will this work?

node* copy (node* head)
{
if (!head)
return NULL;

if (map.contains(head))
return map.get(head);

node* newCopy = new node;
newCopy->d = head->d;

map.put(head,newCopy);
newCopy->next = copy(head->next);
newCopy->random = copy(head->random);

}

- king_k July 12, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

missed the return newCopy at the bottom of the func...

- king_l July 12, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

can u plz tell what will map.contains,map.head do ??

- kaka September 17, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

the above solution is WRONG
it creates extra nodes from random pointer

(1) make the list as circular list; O(n)
(1) store the positions in an array of the random nodes; O(n^2)
(1) create list without using random pointer for now; O(n)
(2) check the array and store the random pointers in new list; O(n^2)

- mail2vcp@gmail.com October 01, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Why can't we have two iterations of the original list?

1) Go through the next pointers of the original list, first creating nodes and updating the next pointers.

2) Since each node will have only one random link and also we have allocated memory for all the nodes, update the random links for the output node.

O(n) time, O(n) space.

- nanmaga October 09, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

by your method it can't be done in o(n) time.

- Anonymous October 17, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

by creating an array of pointers which points to newly allocated nodes in the new list, we can copy any random pointer relationship in O(1) time, which is O(n) for copying all of them.

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

@Anonymous

Can you explain your approach? How can you identify which random pointer is going to which node?

- Sadineni.Venkat February 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

dd

- dd September 02, 2009 | 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