Linked List Interview Questions and Answers
The Best LIVE Mock Interview - You should go through before Interview
Freshers / Beginner level questions & answers
Ques 1. Find the kth to last element of a singly linked list.
Use two pointers; one moves k nodes into the list, and then both iterate until the second one reaches the end.
Example:
Input: 1 -> 2 -> 3 -> 4 -> 5, k = 2
Output: 4
Is it helpful?
Add Comment
View Comments
Ques 2. Remove duplicates from an unsorted linked list.
Use a hash set to keep track of unique elements while traversing the list.
Example:
Input: 1 -> 2 -> 2 -> 3 -> 4 -> 4 -> 5
Output: 1 -> 2 -> 3 -> 4 -> 5
Is it helpful?
Add Comment
View Comments
Ques 3. Write a function to find the middle element of a linked list.
Use two pointers; one moves one step at a time, and the other moves two steps at a time.
Example:
Input: 1 -> 2 -> 3 -> 4 -> 5
Output: 3
Is it helpful?
Add Comment
View Comments
Most helpful rated by users: