Adobe Interview Question for Software Engineers


Country: India
Interview Type: In-Person




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

Hello, you can use two pointers, let's say pointer A and pointer B. Pointer B is 4 steps ahead of pointer A. When pointer B reaches the end of linked list then the pointer A points at the item 4th from the end. You don't need extra memory this way and complexity is O(n) where n is the number of nodes.

- sam October 28, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use a stack:
-traverse the list, pushing each node value on the stack
-pop the value at the top of the stack 5 times; the fifth value popped is the m-4th element

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

// Assume that Class Node already exists.
	public static int getm(Node n, int m){
	
		if(n == null){
			System.out.println("List is Empty");		
			return null;
		}else{
			int count = 0;
			while(n.next!= null){
				count++;
				if(count == m){
					return n.data;
					break;
				}
				n.next = n;
			}
		}	
	}

- revanth October 26, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int getm(Node* n, int m)
{
	Node* ahead = n;
	Node* res = n;
	if ((NULL == n) || (m < 0))
		return NULL;

	for (int i = 0; i < m; i++)
	{
		ahead = ahead->next;
		if (NULL == ahead)
			return NULL;
	}

	while (NULL != ahead)
	{
		res = res->next;
		ahead = ahead->next;
	}

	return res;
}

- JonathanBarOr November 01, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void printMthLastNode(Node head, int m){

Node *temp = head;
Node *currNode = head;

for( int i=0; i<m-1; ++i ){
temp = temp->next;
}

while(temp->next != null){
currNode = currNode->next;
temp = temp->next;
}

printf("Mth LastNode is: %d", currNode->data);

}

struct Node{
int data;
Node *next;
};

- Ashish March 16, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void printMthLastNode(Node head, int m){

Node *temp = head;
Node *currNode = head;

for( int i=0; i<m-1; ++i ){
temp = temp->next;
}

while(temp->next != null){
currNode = currNode->next;
temp = temp->next;
}

printf("Mth LastNode is: %d", currNode->data);

}

struct Node{
int data;
Node *next;
};

- Ashish March 16, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void printMthLastNode(Node head, int m)
{
Node *temp = head;
Node *currNode = head;

for( int i=0; i<m-1; ++i ){
temp = temp->next;
}

while(temp->next != null){
currNode = currNode->next;
temp = temp->next;
}

printf("Mth LastNode is: %d", currNode->data);
}

- Ashish March 16, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void printMthLastNode(Node head, int m)
{
Node *temp = head;
Node *currNode = head;
for( int i=0; i<m-1; ++i )
{
temp = temp->next;
}
while(temp->next != null)
{
currNode = currNode->next;
temp = temp->next;
}
printf("Mth LastNode is: %d", currNode->data);
}

- Ashish March 16, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void printMthLastNode(Node head, int m){
	
	Node *temp = head;
	Node *currNode = head;
	
	for( int i=0; i<m-1; ++i ){
		temp = temp->next;
	}
	
	while(temp->next != null){
		currNode = currNode->next;
		temp = temp->next;
	}
	
	printf("Mth LastNode is: %d", currNode->data);	
}

struct Node{
	int data;
	Node *next;
}

- Ashish March 16, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void printMthLastNode(Node head, int m)
{
Node *temp = head;
Node *currNode = head;
for( int i=0; i<m-1; ++i ){
temp = temp->next;
}
while(temp->next != null){
currNode = currNode->next;
temp = temp->next;
}
printf("Mth LastNode is: %d", currNode->data);
}
struct Node{
int data;
Node *next;
}

- Ashish March 16, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void printMthLastNode(Node head, int m)
{
Node *temp = head;
Node *currNode = head;
for( int i=0; i<m-1; ++i ){
temp = temp->next;
}
while(temp->next != null){
currNode = currNode->next;
temp = temp->next;
}
printf("Mth LastNode is: %d", currNode->data);
}
struct Node{
int data;
Node *next;
}

- Anonymous March 16, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void printMthLastNode(Node head, int m)
{
Node *temp = head;
Node *currNode = head;
for( int i=0; i<m-1; ++i ){
temp = temp->next;
}
while(temp->next != null){
currNode = currNode->next;
temp = temp->next;
}
printf("Mth LastNode is: %d", currNode->data);
}
struct Node{
int data;
Node *next;
}

- Ashish March 16, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Algorithm: -

1. Take two pointers, let's say "fast" and "slow".
2. Move only fast pointer four steps from head(or root) node of linked list and slow at head of the linked list.
3. Now move both pointers simultaneously until fast reaches the end(or tail) of the linked list.
4. slow pointer here will be at m-4 position

Thanks

- Ark March 14, 2019 | 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