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
- 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
- Modular exponentiation (Recursive)
- Modular Exponentiation of Complex Numbers
- Modular Multiplication
- Modular Addition
- Modular Arithmetic
- Modular multiplicative inverse
- Trick for modular division ( (x1 * x2 .... xn) / b ) mod (m)
- Count array elements having modular inverse under given prime number P equal to itself
- XOR of array elements whose modular inverse with a given number exists
- 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
- Insert a node in Linked List before a given node