Given the head of a linked list, write a program to find if linked list has a cycle or not. Return true if there is a cycle or loop in the linked list. Otherwise, return false. A linked list with cycle causes iteration to fail because the iteration will never reach the end. So, detecting a linked list loop is important before applying an iterative approach.
Write a program to find intersection of two sorted linked lists and return the head pointer of the new linked list. Here head pointers of both sorted linked lists are given as input and we shouldn’t do any changes in the structure to generate the output. Note: This is an excellent problem to learn problem-solving using recursion and two pointers in a linked list.
The head pointer of a linked list is given, write a program to remove the Nth node from the end of the linked list and return its head. In other words, when the node is traversed from the end we have to delete the Nth node from there. Note: This is an excellent problem for beginners to learn problem solving using two pointers in a linked list.
A head pointer of a singly linked list is given, write a program to reverse linked list and return the head pointer of the reversed list. We need to reverse the list by changing the links between nodes. Note: This is an excellent question to learn problem-solving using both iteration (Three-pointers) and recursion (Decrease and conquer approach).
Given a singly linked list, write a program to find middle element of the linked list. We need to return the second middle node if the node count is even. Here the goal should be to use a single loop and O(1) extra space to find middle element. Note: This is an excellent problem to learn problem-solving using fast and slow pointers in the linked list.
We have given the head of a singly linked list, write a program to sort the list using insertion sort, and return the head of the sorted linked list. To implement this algorithm, we need to understand the idea of insertion sort on array. At each step of the iteration, insertion sort adds one element to the sorted output and grows the partially sorted list size by 1.
Given the head pointer of a singly linked list, write a program to swap nodes in pairs and return the head of the modified linked list. If the number of nodes is odd, then we need to pairwise swap all nodes except the last node. Note: This is an excellent problem to learn problem solving using both iteration and recursion in a linked list.
Subscribe to get weekly content on data structure and algorithms, machine learning, system design and oops.