Modular Node
##### Submissions: 7956   Accuracy: 37.15%   Difficulty: Basic   Marks: 1

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.

Input:
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.

Output:
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.

Constraints:
1 <= T <= 100
1 <= N <= 500

Example:
Input:

2
7
1 2 3 4 5 6 7
3
5
19 28 37 46 55
2

Output:
6
46

Explanation:
Testcase 1:
Node from the last which is divisible by 3 is 6.

#### ** For More Input/Output Examples Use 'Expected Output' option **

Author: harshitsidhwa

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.