Welcome to the daily solving of our PROBLEM OF THE DAY with Karan Mashru. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Linked List but will also help you build up problem-solving skills.
In this problem, we are given, a linked list, you have to perform the following task:
1-Extract the alternative nodes starting from second node.
2- Reverse the extracted list.
3- Append the extracted list at the end of the original list.
Note: Try to solve the problem without using any extra memory.
Example :
Input:
LinkedList = 10->4->9->1->3->5->9->4
Output:
10 9 3 9 4 5 1 4
Explanation:
Alternative nodes in the given linked list are 4,1,5,4. Reversing the alternative nodes from the given list, and then appending them to the end of the list results in a list 10->9->3->9->4->5->1->4.
Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/given-a-linked-list-reverse-alternate-nodes-and-append-at-the-end/1
Solution IDE LInk: https://ide.geeksforgeeks.org/online-cpp-compiler/bd179ac1-195a-4f04-9b7c-26a3d2812abc