## 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

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.

Comment hidden because of low score. Click to expand.
0

Comment hidden because of low score. Click to expand.
0

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

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;

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

Comment hidden because of low score. Click to expand.
0

awesome

Comment hidden because of low score. Click to expand.
0

amazing logic!!!

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

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)

Comment hidden because of low score. Click to expand.
0
of 2 vote

include int n in the parameter list

Comment hidden because of low score. Click to expand.
0

Comment hidden because of low score. Click to expand.
0

gotchya.. thk u..!!

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).

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

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

``````// Find tail
{
struct node* tail = NULL;
{
}
return tail;
}``````

Comment hidden because of low score. Click to expand.
0

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

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;
}

}

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

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.

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.

### 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.