Given a singly linked list and a number **K**, your are required to complete the function **modularNode(), **that return 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 : list = 1->2->3->4->5->6->7
k = 3
Output : 6
Input : list = 3->7->1->9->8
k = 2
Output : 9
```

**Input:**

The function takes two arguments as input, the reference pointer to the **head **of the linked list and an integer **K**.

There will be **T**, test cases and for each test the function will be called separately.

**Output:**

For each test case the function must return the modular Node data, if no such node is possible then 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

6

46

**Note:**The **Input/Ouput** format and **Example** given are used for system's internal purpose, and should be used by a user for **Expected Output** only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

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.

thanuvinu94 | 238 |

the_coder95 | 215 |

ShivayLamba | 208 |

sandeep.prajapati | 129 |

Ashish Kumar Vaishy | 114 |

the_coder95 | 1441 |

RishabhTanwar1 | 1110 |

thanuvinu94 | 914 |

tathagat289 | 668 |

themanhasnoname | 620 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4897 |

Quandray | 4547 |

Login to report an issue on this page.