Synopsys R&D Interview Question for Software Engineer / Developers


Country: India
Interview Type: Phone Interview




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

check the pseudo code:

test(struct node *head,int n) {
int count=0;

node *nthnode= nthnode(struct node *head,int n);
return(nthnode);
nthnode(struct node *head,int n) {
if(head==null)
return
else
head=head->next;
nthnode(struct node *head,int n);
count++;
if(count==n);
return head;
}








}














}

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

Kindly let me know what is the problem with the approach below, it is causing runtime error.

struct Node*  NthFromLast(struct Node *head, int N) {
	static int count =0;
	if (!head)
		return NULL;

	NthFromLast(head->next, N);
	if (++count == N)
		return head;
	else
		return NULL;
	return NULL;
}

- crystal.rishi2 October 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It returns NULL instead of the nth node, or the head of the list if there are n elements in it.

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

Thanks, I got this modified code

struct Node* rec_nth(struct Node* node, int n) //n being the 'nth' element index from the end
{
     static int count;
     static Node* soln = NULL;
     if(node->next == NULL)
     {
          count = 0;
          return node;
     }
     
     rec_nth(node->next,n);
     if (++count == n)
     {
          soln = node;
     }
     return soln;
}

- crystal.rishi2 October 19, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use Simple STL iterators

list<int> mylist;
 int var;
list<int>::reverse_iterator rit;
  for ( rit=mylist.rbegin() ; rit != mylist.rend(); ++rit )

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

void GetNthFromLast(node* head, int n, node* &ptr) {
  static int count = n;
  if (!head)
    return;

  GetNthFromLast(head->next, count, ptr);

  if (--count == 0) {
    ptr = head;
  }

  return;
}

- Anonymous November 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

nthnode(node *l,int n,node *q)  //q will be passed null at starting
{ if(n==0)
   return q

 else
       {
         node *p=l;
         while(p->next!q)
            {
                p=p->next;
             }
            q=p;n=n-1;
          nthnode(l,n,q)
      }
}

- itbrother October 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

excellent code itbrother.bt u have made some mistake while typing.
good work

- Anonymous October 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

struct Node* NthLast(struct Node* head, int n)
{
    //Non Recursive
    //
    //point first pointer to start
    //move first pointer to nth node
    //point second pointer to start
    //move both pointer towards end until first reach to last node
    //second pointer is nth last node
    //
    struct Node *ptr1 = NULL;
    struct Node *ptr2 = NULL;
    if (n < 0) return NULL;
    ptr1 = head;
    while(ptr1 != NULL && n > 0)
    {
        ptr1 = ptr1->next;
        n--;
    }
    if (ptr1 == NULL) return NULL;
    ptr2 = head;
    while(ptr1->next != NULL)
    {
        ptr1 = ptr1->next;
        ptr2 = ptr2->next;
    }
    return ptr2;
}

- Vishal October 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Use STL
list<int> mylist;
list<int>::reverse_iterator rit;
for ( rit=mylist.rbegin() ; rit != mylist.rend(); ++rit )

- Nirjhar October 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Use STL
list<int> mylist;
list<int>::reverse_iterator rit;
for ( rit=mylist.rbegin() ; rit != mylist.rend(); ++rit )

- nirjhar18 October 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

void GetNthFromLast(node* head, int n, node* &ptr) {
  static int count = n;
  if (!head)
    return;

  GetNthFromLast(head->next, count, ptr);

  if (--count == 0) {
    ptr = head;
  }

  return;
}

- sn November 11, 2014 | 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