Given a singly linked list and a number K, you are required to complete the function modularNode() which returns the modular node of the linked list.
A modular node is the last node of the linked list whose Index is divisible by the number K, i.e. i%k==0.
First line of input contains number of testcases T. For each testcase, first line of input contains length of Linked list N. Next line contains elements of the linked list and last line contains K.
For each test case the function must return the modular Node data, if no such node is possible then return "-1".
The task is to complete the function modularNode() which should return the data of the modular node if exists else return -1.
1 <= T <= 100
1 <= N <= 500
1 2 3 4 5 6 7
19 28 37 46 55
Testcase 1: Node from the last which is divisible by 3 is 6.
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.