NVIDIA Interview Question for Software Engineer / Developers






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

node*temp,*cur /*s points to dummy node at the beginning of the list*/

cur=s;
temp=s->next;

while(temp!=NULL)
{
cur=temp;
temp=temp->next;
}

free(cur->dataptr);
free(cur);

- Anonymous July 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this is a linked list, leaving the last node pointing to freed/unallocated space will lead to crashes.
deleting just the data is not enough.

- Anonymous December 02, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

/* Node data structure */
struct node_data
{
int a;
char b;
};

/*Linked list node structure */
struct node
{
struct node_data* data;
struct node* next;
};

void delete_last(struct node **head)
{
if( *head ==NULL)
return;

if(*head->next = NULL) //Only one node
{
free(*head->data);
free(*head);
*head =NULL;
return;
}
struct node* current = *head;
while(current->next->next )
current = current->next;

free(current->next->data);
free(current->next);
current->next = NULL;
return;

}

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

Nice solution! You could also use function signature like this:
NODE *delNode(NODE *);
Then you do not need to pass NODE **

- AW April 09, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote
Rascala coder mind it... All testing done... Rajnikanth rocks! {{{ void Delete(node **head) { node *p=*head; if(p==NULL) return; if(p->next==NULL) {*head=NULL; free(p->data); free(p); return; } node *q=p; p=p->next; while(p->next!=NULL) { p=p->next; q=q->next; } q->next=q->next->next; //thats null, do check here! free(p->data); free(p); } - aukher March 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Rascala coder mind it... All testing done... Rajnikanth rocks!

void Delete(node **head)
{
  node *p=*head;
  if(p==NULL) return;
  if(p->next==NULL) {*head=NULL; free(p->data); free(p); return; }
 
 node *q=p;
 p=p->next;
 while(p->next!=NULL) { p=p->next; q=q->next; }
 q->next=q->next->next; //thats null, do check here!
 free(p->data);
 free(p);

}

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

Rascala coder mind it... All testing done... Rajnikanth rocks!

void Delete(node **head)
{
  node *p=*head;
  if(p==NULL) return;
  if(p->next==NULL) {*head=NULL; free(p->data); free(p); return; }
 
 node *q=p;
 p=p->next;
 while(p->next!=NULL) { p=p->next; q=q->next; }
 q->next=q->next->next; //thats null, do check here!
 free(p->data);
 free(p);

}

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

Rascala coder mind it... All testing done... Rajnikanth rocks!

void Delete(node **head)
{
  node *p=*head;
  if(p==NULL) return;
  if(p->next==NULL) {*head=NULL; free(p->data); free(p); return; }
 
 node *q=p;
 p=p->next;
 while(p->next!=NULL) { p=p->next; q=q->next; }
 q->next=q->next->next; //thats null, do check here!
 free(p->data);
 free(p);

}

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

Rascala coder mind it... All testing done... Rajnikanth rocks!

void Delete(node **head)
{
  node *p=*head;
  if(p==NULL) return;
  if(p->next==NULL) {*head=NULL; free(p->data); free(p); return; }
 
 node *q=p;
 p=p->next;
 while(p->next!=NULL) { p=p->next; q=q->next; }
 q->next=q->next->next; //thats null, do check here!
 free(p->data);
 free(p);

}

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

cur=s; 
temp=s; 

while(temp->next!=NULL) 
{ 
cur=temp; 
temp=temp->next; 
} 

cur->next=NULL
free(temp);

- nikhil May 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

public static

- Anonymous April 09, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

public static

- Anonymous April 09, 2011 | 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