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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Modular Exponentiation (Power in Modular Arithmetic)
- Create new linked list from two given linked list with greater element at each node
- Find the value of P and modular inverse of Q modulo 998244353
- Swap Kth node from beginning with Kth node from end in a Linked List
- Swap Kth node from beginning with Kth node from end in a Doubly Linked List
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- Merge a linked list into another linked list at alternate positions
- Check if a linked list is Circular Linked List
- Convert singly linked list into circular linked list
- Difference between Singly linked list and Doubly linked list
- Convert Singly Linked List to XOR Linked List
- Modular multiplicative inverse
- How to avoid overflow in modular multiplication?
- Modular Division
- Using Chinese Remainder Theorem to Combine Modular equations
- Modular multiplicative inverse from 1 to n
- Number of solutions to Modular Equations
- Trick for modular division ( (x1 * x2 .... xn) / b ) mod (m)
- Modular exponentiation (Recursive)