Goldman Sachs Interview Question for Software Engineer / Developers






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

void reversePrint(node *n)
{
if(n)
{ reversePrint(n->next);
print(n->content);
}

}

does the job, but function calls incur a lot of stack space

Other way would be to reverse the linked list,print the list and reverse the list again to restore it

/*reversal*/

void reverseList(node ** head)
{
node* curr = *head, *prev = null;

while(curr)
{
nxt_fwd = curr->next;
curr->next = prev;
prev =curr;
curr=nxt_fwd;
}
*head = prev; /*save the new head */

}

- JZ January 10, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

node * prevoius = NULL;
node * current = NULL;
node * following = NULL;

prevoius = head;
current = prevoius->next;
following = current->next;

prevoius->next = NULL;

while(following != NULL)
{

current->next = prevoius;

prevoius = current;
current = following;
following = following->next;

if(following == NULL)
{
current->next = prevoius;
}
}

head = current;
printList(head);

- Nitin Bhatt January 30, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can be used stack for the same

- Anonymous February 15, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

traverse the linked list, pushing the pointers to each node in a stack as u go along. then pop the elements of the stack and print the data content of the nodes pointed by each of them.

- evil grin July 23, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Struct node
{
int data;
Struct node *next;
};

//call the function below from the main loop and pass the pointer to head of list as aparameter to it.

Print_List(Struct node *head)
{
if (head==null)
return;
else
Print_List(head->next);
printf("%d", head->data);
return;
}

- Use Recursion August 01, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void rprint(node* x)
{
if(x->next!=null)
rprint(x->next);
print(x->val);
}

- Aadith April 07, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Aadith is perfectly right

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

public void printBackwards{
for(int i = listToPrint.size() - 1; i >= 0; i--){
System.out.println(listToPrint.get(i));
}
}

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

public void printBackwards{
for(int i = listToPrint.size() - 1; i >= 0; i--){
System.out.println(listToPrint.get(i));
}
}

- Raunak October 28, 2010 | 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