Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Linked List Interview Questions and Answers

Ques 11. Implement a function to reverse a singly linked list.

To reverse a linked list, you can iterate through the list and reverse the direction of pointers.

Example:

Input: 1 -> 2 -> 3 -> 4 -> 5
Output: 5 -> 4 -> 3 -> 2 -> 1

Is it helpful? Add Comment View Comments
 

Ques 12. Detect a cycle in a linked list.

You can use Floyd's cycle-finding algorithm, also known as the 'tortoise and hare' algorithm.

Example:

Input: 1 -> 2 -> 3 -> 4 -> 5 -> 2 (cycle)
Output: True

Is it helpful? Add Comment View Comments
 

Ques 13. Merge two sorted linked lists into a single sorted list.

Traverse both lists simultaneously, compare elements, and merge them into a new sorted list.

Example:

Input: List1: 1 -> 3 -> 5, List2: 2 -> 4 -> 6
Output: 1 -> 2 -> 3 -> 4 -> 5 -> 6

Is it helpful? Add Comment View Comments
 

Ques 14. 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 15. 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
 

Most helpful rated by users:

©2025 WithoutBook