NVIDIA Interview Question for Software Engineer / Developers






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

my solution in C:

void reverse(Node **head) {
 Node *current = *head;
 Node *next;
 Node *temp;
 if (head == NULL || *head == NULL || (*head)->next == NULL)
  return;
 temp = current->next;
 current->next = NULL;
 while (temp != NULL) {
  next = temp->next;
  temp->next = current;
  current = temp;
  temp = next;
 }
 *head = current;

}

- woohoo February 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

and the datatype:

typedef struct node {
 struct node *next;
 void *data;
} Node;

- woohoo February 27, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <stdlib.h>

typedef struct node {
struct node *next;
int data;
} Node;

Node* create_node(int data)
{
Node* ptr = (Node*) malloc (sizeof(Node));
ptr->next=NULL;
ptr->data=data;
return ptr;
}

add_to_list(Node** head,Node* new_node)
{
if(*head==NULL)
*head=new_node;
else
{
new_node->next = *head;
*head=new_node;
}
}

print_list(Node* rover)
{
while(rover!=NULL)
{
printf("%d => ",rover->data);
rover = rover->next;
}
printf("NULL\n");
}

Node* reverse_list(Node* head)
{
if(head==NULL)
return;


Node *prev=head,*cur=head->next,*next=head->next->next;
prev->next=NULL;

while(next!=NULL)
{
cur->next = prev;
prev = cur; cur = next; next = next->next;
}
cur->next = prev;
head = cur;
return head;
}

int main()
{
int i=0;
Node *ptr,*head=NULL;
for(i=10;i>0;i--)
{
ptr = create_node(i);
add_to_list(&head,ptr);
}
print_list(head);
head=reverse_list(head);
print_list(head);
getch();
}

- head March 09, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The code works but there is a small bug for you to figure out...Enjoy !!

- head March 09, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

node *reverse(node *first)


{
node *cur,*temp;


cur=NULL;

while(first!=NULL)


{temp=first;

first=first->link;

temp->link=cur;

cur=temp;
}

return cur;

}

- Nit March 22, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Recursion can be used to reverse the list.


public void reverse(node x){
if(x == null)
return;

reverse(x.next);
System.out.println(x.data);

}

- mbaise May 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Recursion can be used to reverse the list.


public void reverse(node x){
if(x == null)
return;

reverse(x.next);
System.out.println(x.data);

}

- mbaise May 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

struct ListNode {
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};

ListNode* reverseList(ListNode* head) {
    ListNode* curr = head, *prev = NULL, *next;

    while (curr != NULL) {
        next = curr->next;
        curr->next = prev;
        prev = curr;
        curr = next;
    }
    head = prev;
    return head;
}

- yunpeng September 01, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void reverse_diffn(dnode **dpnode)
{
	dnode *curnode = *dpnode;
	unsigned int prevaddr = NULL, curraddr = NULL;

	while (curnode != NULL)
	{
		curraddr = (unsigned int)curnode;
		curnode = curnode->down;
		*((unsigned int *)curraddr + 1) = (prevaddr);
		prevaddr = curraddr;
	}
	*dpnode = ((dnode *)curraddr);
}

- vlsireddy October 03, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

pussy cat pusst cat
Rascala pussy

- aukher March 14, 2012 | 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