Amazon Interview Question for Software Engineer / Developers


Country: India
Interview Type: Written Test




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

Its better if you did your homework by yourself. :)

- pers3us March 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Its better you should write the code instead of writing comments.
Let the code say it all

- popoff March 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Exactly... I agree with pers3us. It's better you do ur homework by yourself rather than putting such questions under a big company's name.

- Anonymous March 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

It's not like it's impossible that Amazon would ask this question. They certainly ask harder questions, but they ask easy ones too.

- eugene.yarovoi March 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Let me clarify few things here -
1. Big companies can ask simple questions.They have done it in the past and they are already doing it.
2. Questions posted here are just to give an idea about what is being asked these days and not about finding solution.
3. I was able to solve it and also knewing the solution...but I didn't wrote the solution because it was really too simple.

- popoff March 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Straight forward answer is:
Keep checking whether the value in the next node is equal to the given value. If true you just assign the next pointer in the current node to the next pointer ie
if(ptr->next.value==number)
ptr->next=ptr->next->next
else
ptr=ptr->next

- vijay March 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think you are confused with the question ...the node no. is given and not its value ..like deleteNode(head,5) which means you have to delete 5th node.

- popoff March 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Then it is even more easier. Just iterate through the for loop and delete the nth node

- vijay March 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

it is easier. loop n times to reach the node you wanna delete, then trash it...

- flyinocean.mitbbs March 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

You dont need to "wrote" the solution.. Too Simble.... Good luck with Amazon

- prash March 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Amazon asked this! I am so thru with the interview I have over the weekend :)

- chaos March 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

for(int i=0; i < nodeNum-1; i++)
{
node = node->next;
}.
tempNode = node->next;
node->next = node->next->next;
free(tempNode);

- jayant April 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

if node 1 is to be deleted , den according to your code..
if list is 1->2->3->4 then output will be 1->3->4, ie, the second node gets deleted....

- Anonymous May 08, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

One simple solution:
Copy the next node of given node no. to given node. So given node value is overwritten and delete next node.
Lets say:
1-2-3-4-5-6-7-8
you want to delete 5 and your pointer points to 5.
So copy 6 in place of 5 and delete 6 as
5->next = 5->next->next.
But this won't work when you want to delete last node and your pointer points to last node.

- himanshu September 08, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Yes it might be easy, but this is a question to see how carefully you deal with all cases and code that up.

For instance, what happens if we delete the head? The last node? What if the node pointer is not found in the list?

C code. I am pretty sure there are bugs.

// Delete node from singly linked list starting at head.
// returns head of linked list with node deleted.
List * deleteNode (List *head, List *node) {
    
    if (!head || !node) return head;
   
    List dummy;
    dummy->next = head;
    List * cur = head;
    List *prev = &dummy;
    while (cur != node && cur != NULL) {
        prev = cur;
        cur = cur->next;
    }
    // at this point, either cur is NULL or node.
    if (cur == node) {
        prev->next = node->next;
    }
    return dummy.next;
}

- Anonymous September 08, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Bug: Memory leak, but I suppose it could be make the responsibility of the caller.

- Anonymous September 08, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Signature is not correct. You missed the word 'no' in the question, which presumably stands for number.

- Anonymous September 08, 2012 | Flag


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