Modular Node In A Linked List

easy
1. You are given a linked list with N nodes.
 2. You are also given a number K.
 3. You have to write a function that that returns the data of the modular node of the linked list.
 4. A modular node is the last node of the linked list whose index(1-based indexing) is divisible by the number K, i.e. i % K == 0.
 4. display is a utility function which displays the contents of Linked List, feel free to use it for debugging purposes.
 5. main takes input from the users and creates the Linked List. You can use display to know its contents.
 6. This is a functional problem. 
 7. You should code only the moduarNode function. It takes as input the head of the linked list, N and K. It should return the data value of modular node if present, else should return -1.
 8. Don't change the code of Node, main and display.

Input Format

First line takes N, the number of elements in the list. Second line takes input N space separated numbers reperesenting elements of the linked list. Third line takes K. Input is handled for you.

Output Format

Data value of modular node if present, else -1. Output is handled for you.

Constraints

1 <= N <= 1000

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
5
19 28 37 46 55
2
Output
46
Previous
Merge sorted linked lists in reverse
Next
Multiplication Of Linked Lists

Related Questions