Qualcomm Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

if(head==null) return null;

Start with two pointers.
P1 and P2 pointing at the head.
keeping p1 at the position, increment p2 n times. (During the process, if anywhere p2 points to null, return null).
Now increment p1 and p2 together until p2->next == null.
p1 points to the nth node from the nth node from last.
regards.

- DH October 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Best Answer Brother

- Arun Kumar Gupta July 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thanks......this logic is really good and working

- Tauqir December 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

struct node* getNthLast(struct node* head,int n)
{
   struct node *tmp1, *tmp2;
   tmp1=tmp2=head; 

while(tmp2)
  { if(n>0) 
     {
      tmp2=tmp2->next; 
      n--;
     }
    else
     { 
        tmp1=tmp1->next;
        tmp2=tmp2->next;
     }
    }
   return tmp1;

- einstein.goli October 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

awesome

- Arun Kumar Gupta July 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

amazing logic!!!

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

this doesn't chk boundary condition

1. if list is NULL
2. If list length is less than n
3 List size is exactly n
4. list is not circular

- Sougata Chatterjee May 24, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

p1 points to the nth node from last. (last sentence in the comment above)

- DH October 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

include int n in the parameter list

- einstein.goli October 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You can always edit your comment and correct any typos. Check 'Edit' link on your reply.

- Laxmi Narsimha Rao Oruganti November 07, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

gotchya.. thk u..!!

- einstein.goli November 07, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Keep a queue of fixed size n and loop through the linked list. As you get each node perform the following operations enqueue the current node in the end and dequeue the first element if it is full.

Precisely the pseudo code should look like:

FetchNthFromEnd (node top)
begin
queue q(n)
while(top is not null)
loop
enqueue(q,top) // it should handle the case when the queue is full, in that case the first element should be dequeued and then new element should be enqueued.
next(top)
endloop
return dequeue(q)
end

enqueue and dequeue both are O(1) so it is O(N).

- epsilon February 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Traverse the linked list and put the node in the stack until null.
Now pop out nodes from the stack and count until n is reached. That the node to look for. If stack is empty before n reached, return NULL

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

// Find tail
struct node* findTail(struct node* head)
{
	struct node* tail = NULL;	
	while(head != NULL)
	{
		tail = head;
		head = head->next;
	}
	return tail;
}

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

node *Function(int nthnode_to_move)
{
int totalnodes = 0, difference = 0, nthnode = 0;
node *temp1 = head;
node *temp2 = head;

if ( head == NULL )
return 0;

while ( temp->next != NULL )
totalnodes++;

if ( totalnodes < nthnode_to_move )
return 0;
else
{
difference = totalnodes - nthnode_to_move;
nthnode = difference + 1;

while ( nthnode < 0 )
{
temp2 = temp2->next;
nthnode--;
}

return temp2;
}

}

- satz November 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Start with 2 pointers. P1 and P2.

P1 increments by 1, P2 increments by 2.
When P2 reaches end. You'll know the total number of elements in the list.
And P1 is halfway. Calculate from P2 and move P1 forward or backward accordingly.

- Erick April 15, 2013 | 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