X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Modular Node
Basic Accuracy: 47.3% Submissions: 21384 Points: 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.
Note: If no such node is available, return -1.

Example 1:

Input: LinkedList: 1->2->3->4->5->6->7
k = 3
Output: 6
Explanation: Node from the last with
index divisible by 3 is 6

Example 2:

Input: LinkedList: 19->28->37->46->55
k = 2
Output: 46
Explanation: Node from the last with
index divisible by 2 is 46

You don't need to read input or print anything. Complete the function modularNode() which takes the head Node and integer k as input parameters and returns the modular Node, if exists, -1 otherwise.

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

We are replacing the old Disqus forum with the new Discussions section given below.