Amazon Interview Question for Software Engineer / Developers






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

<pre lang="" line="1" title="CodeMonkey95834" class="run-this">struct List
{
int data;
struct List *next;
};
struct List* Reverse(struct List* head)
{
struct List *temp;
if(head==NULL)
return NULL;
if(head->next==NULL)
return head;
temp=reverse(head->next);
head->next->next=head;
return temp;
}</pre><pre title="CodeMonkey95834" input="yes">
</pre>

- Anonymous June 12, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

List reverseList(List head) {
 if(head == null) {
  return null;
 }
 if(head.next == null) {
  return head;
 }
 List tail = head;
 List h = head.next;
 while(tail.next != null) {
  List temp = tail.next;
  tail.next = tail.next.next;
  temp.next = h;
  h = temp;
 }
 return h;
}

- sethuraj.32 June 12, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public void displayLisReversed(Link currNode)
{
Link pCurrent = currNode; //start at beginning of list

if (pCurrent.pNext != null) //until end of list,
{
displayLisReversed(pCurrent.pNext);
}
pCurrent.displayLink();
}

public class Link
{
public int iData; //data item
public double dData; //data item
public Link pNext; //ptr to next link in list

//-------------------------------------------------------------
public Link(int id, double dd)
{
iData = id;
dData = dd;
pNext = null;
}

//-------------------------------------------------------------
public void displayLink() //display ourself {22, 2.99}
{
Console.WriteLine("iData = " + dData);
}
//-------------------------------------------------------------
}

- Anonymous June 14, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public Node ReverseList(Node Head)
        {
            Node loop = Head;
            Node reverse = null;
            Node temp = null;

            while (loop != null)
            {
                temp = loop.Next;
                loop.Next = reverse;
                reverse = loop;
                loop = temp;
            }

            return reverse;
        }

- Mi Jalgaonkar June 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void reverse(mynode* head)
{
 mynode*k, *r,*s;
 k=head;r=NULL;
 while(k!=NULL)
 {
  s=r;
  r=k;
  k=k->next;
  r->next=s;
 }
return r;
}
}

- Mr.4342 July 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public ListNode reverse(ListNode head){
if(head==null)
return null;
if(head.next==null)
return head;
ListNode current=head;
ListNode prev=null;
ListNode temp=null;
while(current!=null){
temp=current.next;
current.next=prev;
prev=current;
current=temp;
}
return prev;
}

- skyboardsrx August 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Tested and working code, should take care of edge case tests.

Node MakeSingleLinkedListReverse(Node currentNode)
{
    Node previousNode = null;
    Node nextNode = null;
           
    while (currentNode != null)
    {
        nextNode = currentNode.NextNode;
        currentNode.NextNode = previousNode;

        previousNode = currentNode;
        currentNode = nextNode;
    }

    return previousNode;
}

- Srigopal Chitrapu April 29, 2014 | 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