## Dover Organization Interview Question for Developer Program Engineers

Country: India
Interview Type: In-Person

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

``````package com.career.ds.linkedlist;

public class NthNodeFromEnd {
public static void main(String args[]) {
CreateList ll = new CreateList();
System.out.println();
System.out.println(2 + " node from end:" + nthNode.getData());
}

}

class Node {
public Node(int data) {
this.data = data;
}

int data;
Node next;

public int getData() {
return data;
}

public void setData(int data) {
this.data = data;
}

public Node getNext() {
return next;
}

public void setNext(Node next) {
this.next = next;
}
}

class CreateList {

public Node createList(int length, int data) {
for (int i = 1; i < length; i++) {
Node temp = new Node((data++));
pointer.setNext(temp);
pointer = temp;
}
}

}
}

public Node getNthNodeFromEnd(Node head, int nth) {
Node pointer = nthNode;
int i = 0;
while (nthNode != null && i != nth) {
pointer = pointer.getNext();
i++;
}

while (pointer != null) {
pointer = pointer.getNext();
nthNode = nthNode.getNext();
}

return nthNode;
}
}``````

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

use two pointers:p1 and p2
At first ,p1 point to the Nth node from the head,p2 point to the head.
Then,p1 and p2 move to their next node together,when p1 point to the end,p2 point to the Nth node from the end.

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

two pointer: the pfirst goes n steps first then with psecond from start together, when the pfirst arrives at the end, the psecond point the nth node form the end.

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

#include <iostream>

using namespace std;

struct Node
{
int mData;
Node* mNext;

Node(int data , Node* next=nullptr):mData(data),mNext(next) {}
};
struct List
{

{
else
{
while(temp->mNext != nullptr)
temp = temp->mNext;
temp->mNext = new Node(data);
}
}
void Display()
{
cout<<"\n Content of List are : ";
while(temp != nullptr)
{
cout<<"\t"<<temp->mData;
temp = temp->mNext;
}
}
void Find_Last_nth_Element(int count)
{
{

int index = 0;
while( (index < count) && temp )
{
temp = temp->mNext;
++index;
}
if(index != count)
cout<<"\n lesser elements in List"<<endl;
else
{
while(temp)
{
temp = temp->mNext;
nthNode = nthNode->mNext;
}
cout<<"\n the "<<count<<" node from last in list is "<<nthNode->mData;
}
}
}
};

void main()
{
cout<<"\n Program Started"<<endl;
List myList;
for(int i=0;i<20;++i)

myList.Display();
int nthNode=0;
cout<<"\nEnter nth Element from last:";
cin>>nthNode;

myList.Find_Last_nth_Element(nthNode);
cout<<"\n Program Ended"<<endl;
}

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.