Given a singly linked list and a number k. Write a function to find the (N/k)^{th} element, where N is the number of elements in the list. We need to consider ceil value in case of decimals.
Input:
The first line of input contains an integer T denoting the number of test cases. The first line of each test case consists of an integer N. The second line consists of N spaced integers.The last line consists of an integer k.
Output:
Print the data value of (N/k)th node in the Linked List.
User Task:
The task is to complete the function fractional_node() which should find the n/kth node in the linked list and return its data value.
Constraints: 
1 <= T <= 100
1 <= N <= 100
K > 0
Example:
Input:
2
6
1 2 3 4 5 6
2
5
2 7 9 3 5
3
Output:
3
7
Explanation:
Testcase 1: 6/2^{th} element is the 3^{rd}(1-based indexing) element which is 3.
Testcase 2: 5/3^{rd} element is the 2nd element as mentioned in question that we need to consider ceil value in case of decimals. So 2^{nd} element is 7.

Difficulty: EASY
Tags: Data structures
Skill types: Data structures

Starter code:
#User function Template for python3



'''class Node: 

   

    # Function to initialize the node object 

    def __init__(self, data): 

        self.data = data   

        self.next = None

'''

        



def fractionalNodes(head,k):

        #add code here

                          

Solutions:
def fractionalNodes(head, k):
	last = head
	count = 0
	while last and last.next:
		count += 1
		last = last.next
	curr = head
	ind = count // k
	for i in range(ind):
		head = head.next
	return head


def fractionalNodes(head, k):
	if k <= 0 or head == None:
		return None
	N1 = None
	i = 0
	temp = head
	while temp != None:
		if i % k == 0:
			if N1 == None:
				N1 = head
			else:
				N1 = N1.next
		i = i + 1
		temp = temp.next
	return N1


def fractionalNodes(head, k):
	if k <= 0 or head is None:
		return None
	fractionalNodes = None
	temp = head
	i = 0
	while temp is not None:
		temp = temp.next
		if i % k == 0:
			if fractionalNodes is None:
				fractionalNodes = head
			else:
				fractionalNodes = fractionalNodes.next
		i = i + 1
	return fractionalNodes


def fractionalNodes(head, k):
	d = head
	i = 1
	while d.next != None:
		i += 1
		d = d.next
	if i // k == i / k:
		n = i // k
	else:
		n = i // k + 1
	d = head
	for i in range(n - 1):
		d = d.next
	return d


from math import ceil

def fractionalNodes(head, k):
	n = 0
	curr = head
	while curr:
		curr = curr.next
		n += 1
	N = ceil(n / k)
	if N == 1:
		return head
	curr = head
	while N > 1:
		curr = curr.next
		N -= 1
	return curr


def fractionalNodes(head, k):
	current = head
	N = 0
	while current:
		N += 1
		current = current.next
	if not N % k:
		idx = int(N / k)
	else:
		idx = int(N / k + 1)
	current = head
	if idx == 1:
		return current
	else:
		while idx - 1 and current.next:
			current = current.next
			idx -= 1
	return current


import math

def fractionalNodes(head, k):
	curr = head
	c = 1
	while curr:
		if math.ceil(n / k) == c:
			return curr
		c += 1
		curr = curr.next


import math

def fractionalNodes(head, k):
	ln = 0
	curr = head
	while curr:
		curr = curr.next
		ln += 1
	fraction = math.ceil(ln / k)
	for _ in range(fraction - 1):
		head = head.next
	return head


def fractionalNodes(head, k):
	from math import ceil
	N = 0
	b = []
	tmp = head
	while tmp:
		b.append(tmp)
		N += 1
		tmp = tmp.next
	return b[ceil(N / k) - 1]


import math

def fractionalNodes(head, k):
	curr = head
	l = 1
	while curr.next != None:
		l += 1
		curr = curr.next
	n = math.ceil(l / k)
	i = 1
	curr = head
	while curr.next != None:
		if i == n:
			return curr
		i += 1
		curr = curr.next
	if i == n:
		return curr


def fractionalNodes(head, k):
	count = 0
	curr = head
	while curr and curr.next:
		count += 1
		curr = curr.next
	a = count // k
	cur = head
	for i in range(a):
		cur = cur.next
	return cur


def fractionalNodes(head, k):
	c = 0
	temp = head
	while temp != None and temp.next != None:
		c += 1
		temp = temp.next
	temp = head
	n = c // k
	for i in range(n):
		head = head.next
	return head


import math

def fractionalNodes(head, k):
	temp = head
	n = 0
	while temp is not None:
		temp = temp.next
		n += 1
	s = math.ceil(n / k) - 1
	if s == 0:
		return head
	while s:
		s -= 1
		head = head.next
	return head


def fractionalNodes(head, k):
	n = 0
	curr = head
	while curr != None:
		n += 1
		curr = curr.next
	if n % k:
		k = n // k + 1
	else:
		k = n // k
	curr = head
	while k != 1:
		curr = curr.next
		k -= 1
	return curr


import math

def fractionalNodes(Head, k):
	curr = Head
	ans = Head
	n = 0
	if Head.next == None:
		return Head
	while curr != None:
		n += 1
		if n % k == 0 and n // k != 1:
			ans = ans.next
		curr = curr.next
	if k >= n:
		return Head
	if n / k != n // k:
		return ans.next
	else:
		return ans


from math import ceil

def fractionalNodes(head, k):
	n = 0
	cur = head
	while cur != None:
		n += 1
		cur = cur.next
	a = ceil(n / k)
	(cur, n) = (head, 1)
	while n < a:
		n += 1
		cur = cur.next
	return cur


import math

def fractionalNodes(head, k):
	c = 0
	t = head
	while t != None:
		c = c + 1
		t = t.next
		d = math.ceil(c / k)
	t = head
	while t.next != None:
		d = d - 1
		if d == 0:
			return t
		t = t.next
	return t


import math

def fractionalNodes(head, k):
	n = 0
	h = head
	while h != None:
		h = h.next
		n += 1
	i = math.ceil(n / k)
	for z in range(i - 1):
		head = head.next
	return head


from math import ceil

def fractionalNodes(head, k):
	n = 0
	l = []
	while head:
		n += 1
		l.append(head.data)
		head = head.next
	c = Node(l[ceil(n / k) - 1])
	return c


import math

def fractionalNodes(head, k):
	curr = head
	N = 0
	while curr != None:
		N += 1
		curr = curr.next
	if N / k <= 1:
		return head
	curr = head
	a = math.ceil(N / k)
	for i in range(a - 1):
		curr = curr.next
	return curr


def fractionalNodes(head, k):
	temp = head
	n = 1
	while temp.next != None:
		temp = temp.next
		n += 1
	x = (n + k - 1) // k
	for i in range(1, x):
		head = head.next
	return head


def fractionalNodes(head, k):
	temp = head
	N = 0
	while head:
		N += 1
		head = head.next
	N = N // k + min(1, N % k)
	head = temp
	while head and N - 1:
		head = head.next
		N -= 1
	return head


import math

def fractionalNodes(head, k):
	temp = head
	temp1 = head
	length = 0
	while temp and temp.next:
		temp = temp.next
		length = length + 1
	a = length // k
	b = math.ceil(a)
	for i in range(b):
		head = head.next
	return head


def fractionalNodes(head, k):
	c = 0
	t = 0
	temp = head
	while temp != None:
		c += 1
		temp = temp.next
	if c / k > c // k:
		t = c // k + 1
	else:
		t = c // k
	for i in range(t - 1):
		head = head.next
	return head


import math

def fractionalNodes(head, k):
	n = 0
	copy = head
	while copy != None:
		n = n + 1
		copy = copy.next
	x = math.ceil(n / k)
	i = 1
	while head != None:
		if x == i:
			return head
		head = head.next
		i = i + 1


def fractionalNodes(head, k):
	n = 0
	temp = head
	while temp:
		n += 1
		temp = temp.next
	pos = 0
	if n % k == 0:
		pos = n // k
	else:
		pos = n // k + 1
	temp = head
	while pos > 1:
		temp = temp.next
		pos -= 1
	return temp


import math

def fractionalNodes(start, k):
	temp = start
	count = 0
	while temp:
		temp = temp.next
		count += 1
	nByK = math.ceil(count / k)
	temp = start
	while temp is not None and nByK > 1:
		temp = temp.next
		nByK -= 1
	return temp


import math

def fractionalNodes(head, k):
	cnt = 0
	last = head
	while last and last.next:
		cnt = cnt + 1
		last = last.next
	num = cnt // k
	curr = head
	for i in range(num):
		curr = curr.next
	return curr


def fractionalNodes(head, k):
	count = 0
	c = 0
	temp = head
	while temp.next is not None:
		count += 1
		temp = temp.next
	k = count // k
	temp = head
	while c != k:
		temp = temp.next
		c += 1
	return temp


def fractionalNodes(head, k):
	import math
	n = 1
	tempHead = head
	while tempHead.next:
		tempHead = tempHead.next
		n += 1
	valueAtIndex = math.ceil(n / k)
	index = 1
	while True:
		if index == valueAtIndex:
			return head
		head = head.next
		index += 1


def fractionalNodes(head, k):
	cur = head
	if n % k == 0:
		for i in range(n // k - 1):
			cur = cur.next
	else:
		for i in range(n // k):
			cur = cur.next
	return cur


import math

def fractionalNodes(head, k):
	n = 1
	temp = head
	while temp.next != None:
		n += 1
		temp = temp.next
	j = math.ceil(n / k)
	i = 1
	temp = head
	while i < j:
		temp = temp.next
		i += 1
	return temp


import math

def fractionalNodes(head, k):
	temp = head.next
	count = 1
	net = 1
	nums = head
	while temp != None:
		temp = temp.next
		count = count + 1
	p = math.ceil(count / k)
	while net < p:
		nums = nums.next
		net = net + 1
	return nums


import math

def fractionalNodes(head, k):
	temp = head
	N = 0
	while temp is not None:
		temp = temp.next
		N += 1
	limit = math.ceil(N / k)
	temp = head
	cnt = 1
	while cnt < limit:
		temp = temp.next
		cnt += 1
	return temp


import math

def fractionalNodes(head, k):
	itr = head
	n = 0
	while itr:
		itr = itr.next
		n += 1
	p = math.ceil(n / k)
	(i, itr) = (1, head)
	while i < p:
		itr = itr.next
		i += 1
	return itr


import math

def fractionalNodes(head, k):
	count = 1
	temp = head
	rq = math.ceil(n / k)
	while count < rq:
		temp = temp.next
		count += 1
	return temp


import math

def fractionalNodes(head, k):
	temp = head
	c = 0
	while temp:
		c += 1
		temp = temp.next
	p = 0
	if c % k == 0:
		p = c // k
	else:
		p = c // k + 1
	temp2 = head
	for i in range(1, p):
		temp2 = temp2.next
	return temp2


import math

def fractionalNodes(head, k):
	h = head
	x = head
	c = 1
	while h.next != None:
		c += 1
		h = h.next
	l = math.ceil(c / k)
	for i in range(1, l):
		x = x.next
	return x


import math

def fractionalNodes(head, k):
	h = head
	c = 0
	while h:
		c += 1
		h = h.next
	j = math.ceil(c / k)
	m = head
	f = 0
	co = 0
	while co < j - 1:
		co += 1
		f += 1
		m = m.next
	return m


import math

def fractionalNodes(head, k):
	temp = []
	pre = head
	while pre:
		temp.append(pre)
		pre = pre.next
	return temp[math.ceil(len(temp) / k) - 1]


def fractionalNodes(head, k):
	if not head:
		return False
	(curr, tmp) = (head, head)
	length = 0
	while tmp:
		tmp = tmp.next
		length += 1
	flag = length / k
	if flag % 1 != 0.0:
		flag += 1
	count = 1
	while curr:
		if count == int(flag):
			return curr
		curr = curr.next
		count += 1


import math

class Node:

	def __init__(self, data):
		self.data = data
		self.next = None

def fractionalNodes(head, k):
	if k <= 0 or head is None:
		return None
	fractionalNodes = None
	temp = head
	i = 0
	while temp is not None:
		temp = temp.next
		if i % k == 0:
			if fractionalNodes is None:
				fractionalNodes = head
			else:
				fractionalNodes = fractionalNodes.next
		i = i + 1
	return fractionalNodes


import math

def fractionalNodes(head, k):
	x = math.ceil(n / k)
	while x > 1:
		head = head.next
		x -= 1
	return head


import math

def fractionalNodes(head, k):
	n1 = math.ceil(n / k)
	t = head
	for i in range(1, n1 + 1):
		if i == n1:
			return t
		t = t.next


from math import ceil

def fractionalNodes(head, k):
	node = head
	m = ceil(n / k)
	for i in range(1, m + 1):
		if i == m:
			return node
		node = node.next


import math

def fractionalNodes(head, k):
	s = 0
	h = head
	while h:
		s = s + 1
		h = h.next
	x = math.ceil(s / k)
	for _ in range(x - 1):
		head = head.next
	return head


def fractionalNodes(head, k):
	count = 0
	curr = head
	while curr is not None:
		count += 1
		curr = curr.next
	index = (count + k - 1) // k
	curr = head
	for i in range(1, index):
		curr = curr.next
	return curr


from math import ceil

def fractionalNodes(head, k):
	c = 0
	temp = head
	while temp:
		temp = temp.next
		c += 1
	a = ceil(c / k)
	for i in range(1, a + 1):
		if i == a:
			return head
		head = head.next


import math

def fractionalNodes(head, k):
	length = 0
	curr = head
	while curr:
		curr = curr.next
		length += 1
	nkth = math.ceil(length / k)
	for i in range(nkth - 1):
		head = head.next
	return head


import math

def fractionalNodes(head, k):
	n = 0
	h = head
	j = head
	while h:
		h = h.next
		n += 1
	i = math.ceil(n / k)
	for f in range(i - 1):
		j = j.next
	return j


def fractionalNodes(head, k):
	temp = head
	index = 0
	while temp:
		temp = temp.next
		index += 1
	loc = index // k
	pos = 1
	if index % k == 0:
		prev = head
		while pos < loc:
			prev = prev.next
			pos += 1
		return prev
	else:
		prev = head
		while pos < loc + 1:
			prev = prev.next
			pos += 1
		return prev


import math

def fractionalNodes(head, k):
	N = 0
	h = head
	while h:
		N += 1
		h = h.next
	x = math.ceil(N / k) - 1
	h = head
	while x > 0:
		h = h.next
		x -= 1
	return h


import math

def fractionalNodes(head, k):
	c = 0
	cur = head
	while cur:
		c += 1
		cur = cur.next
	N = math.ceil(c / k)
	i = 1
	cur2 = head
	while cur2:
		if i == N:
			return cur2
		else:
			cur2 = cur2.next
			i += 1


import math

def fractionalNodes(head, k):
	a = math.ceil(n / k)
	p = head
	for i in range(a - 1):
		p = p.next
	return p


import math

def fractionalNodes(head, k):
	n = head
	c = 0
	while n is not None:
		n = n.next
		c = c + 1
	a = math.ceil(c / k)
	for i in range(a - 1):
		head = head.next
	return head


import math

def fractionalNodes(head, k):
	num = 0
	temp = head
	while temp:
		temp = temp.next
		num = num + 1
	numFraction = math.ceil(num / k)
	for _ in range(numFraction - 1):
		head = head.next
	return head


import math

def fractionalNodes(node, k):
	count = 0
	temp = node
	while temp:
		count += 1
		temp = temp.next
	nodeIndex = math.ceil(count / k)
	index = 1
	while node:
		if index == nodeIndex:
			return node
		node = node.next
		index += 1


import math

def fractionalNodes(node, k):
	nodes = []
	while node:
		nodes.append(node)
		node = node.next
	index = math.ceil(len(nodes) / k) - 1
	return nodes[index]


import math

def fractionalNodes(head, k):
	n = 0
	curr = head
	while curr:
		curr = curr.next
		n += 1
	curr = head
	c = n / k
	c = math.ceil(c)
	i = 1
	while i != c:
		curr = curr.next
		i += 1
	return curr


def fractionalNodes(head, k):
	n = 0
	curr = head
	while curr:
		curr = curr.next
		n += 1
	curr = head
	c = n // k
	if c * k != n:
		c = c + 1
	i = 1
	while i != c:
		curr = curr.next
		i += 1
	return curr


from decimal import Decimal, ROUND_CEILING

def fractionalNodes(head, k):
	itr = head
	c = 0
	while itr:
		c = c + 1
		itr = itr.next
	N = c
	c = 1
	itr = head
	l = N // k
	m = N / k
	if m > l:
		m = l + 1
	else:
		m = l
	while itr:
		if c == m:
			return itr
		c = c + 1
		itr = itr.next
	return


import math

def fractionalNodes(head, k):
	c = 0
	temp = head
	while temp:
		c += 1
		temp = temp.next
	a = math.ceil(c / k)
	temp = head
	while a > 1:
		temp = temp.next
		a -= 1
	return temp


import math

def fractionalNodes(head, k):
	n = head
	num = 0
	while n:
		num += 1
		n = n.next
	t = math.ceil(num / k)
	if t == 1:
		return head
	for i in range(1, t):
		head = head.next
	return head


import math

def length(head):
	if head == None:
		return 0
	count = 0
	while head != None:
		count += 1
		head = head.next
	return count

def fractionalNodes(head, k):
	if head == None:
		return None
	l = length(head)
	n = math.ceil(l / k) - 1
	while n != 0:
		head = head.next
		n -= 1
	return head


def fractionalNodes(head, k):
	import math
	current = head
	temp = head
	i = 0
	j = 0
	while current:
		i += 1
		current = current.next
	l = math.ceil(i / k)
	while temp:
		l -= 1
		if l == 0:
			return temp
		temp = temp.next


import math

def fractionalNodes(head, k):
	i = 0
	curr = head
	tmp = head
	while curr:
		i += 1
		curr = curr.next
	x = math.ceil(i / k)
	d = 1
	while tmp:
		if d == x:
			return tmp
		else:
			tmp = tmp.next
			d += 1


def fractionalNodes(head, k):
	i = 0
	temp = head
	fn = None
	while temp:
		if i % k == 0:
			if not fn:
				fn = temp
			else:
				fn = fn.next
		i += 1
		temp = temp.next
	return fn


def fractionalNodes(head, k):
	cnt = 0
	if not head:
		return
	copy = head
	while copy:
		copy = copy.next
		cnt += 1
	nk = n // k + (n / k > n // k) * 1
	for i in range(nk - 1):
		head = head.next
	return head


import math

def fractionalNodes(head, k):
	temp = head
	count = 0
	while temp is not None:
		count += 1
		temp = temp.next
	c = 1
	count = math.ceil(count / k)
	temp = head
	while temp is not None:
		if c == count:
			return temp
		c += 1
		temp = temp.next


import math

def fractionalNodes(head, k):
	N = 0
	cur = head
	while cur:
		cur = cur.next
		N += 1
	skip = math.ceil(N / k)
	for i in range(skip - 1):
		head = head.next
	return head


import math

def fractionalNodes(head, k):
	n = 0
	temp = head
	while temp:
		temp = temp.next
		n += 1
	p = math.ceil(n / k)
	temp = head
	while p > 1:
		temp = temp.next
		p -= 1
	return temp