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 firstname.lastname@example.org. 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.
- Find the balanced node in a Linked List
- Find the fractional (or n/k - th) node in linked list
- Find first node of loop in a linked list
- Find kth node from Middle towards Head of 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 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 Linked List
- Linked List | Set 3 (Deleting a node)
- Remove first node of the linked list
- Squareroot(n)-th node in a Linked List
- Delete Nth node from the end of the given linked list
- Remove last node of the linked list
- Linked List | Set 2 (Inserting a node)
Improved By : Rajput-Ji