Given a singly linked list and a number k, find the last node whose n%k == 0, where n is the number of nodes in the list.
Input : list = 1->2->3->4->5->6->7 k = 3 Output : 6 Input : list = 3->7->1->9->8 k = 2 Output : 9
1. Take a pointer modularNode and initialize it with NULL. Traverse the linked list.
2. For every i%k=0, update modularNode.
Modular node is 4
This article is contributed by Prakriti Gupta. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find first node of loop in a linked list
- Find the fractional (or n/k - th) node in linked list
- Find extra node in the second Linked list
- Find the balanced node in a Linked List
- Recursive Approach to find nth node from the end in the linked list
- Find the second last node of a linked list in single traversal
- Find kth node from Middle towards Head of a Linked List
- Find the largest node in Doubly linked list
- Create new linked list from two given linked list with greater element at each node
- Swap Kth node from beginning with Kth node from end in a Doubly Linked List
- Swap Kth node from beginning with Kth node from end in a Linked List
- Remove Nth node from end of the Linked List
- Remove first node of the linked list
- Remove last node of the linked list
- Delete Nth node from the end of the given linked list
- Linked List | Set 2 (Inserting a node)
- Remove every k-th node of the linked list
- Linked List | Set 3 (Deleting a node)
- Squareroot(n)-th node in a Linked List
- Program for n'th node from the end of a Linked List