Given a singly linked list with N nodes and a number X. The task is to find the node at the given index (X)(1 based index) of linked list. 
Input:
First line of input contains number of testcases T. For each testcase, first line of input contains space seperated two integers, length of linked list and X.
Output:
For each testcase, there will be single line of output containing data at Xth node.
User Task:
The task is to complete the function GetNth() which takes head reference and index as arguments and should return the data at Xth position in the linked list.
Constraints:
1 <= T <= 30
1 <= N <= 100
X <= N
1 <= value <= 10^{3}
Example:
Input:
2
6 5
1 2 3 4 657 76
10 2
8 7 10 8 6 1 20 91 21 2
Output:
657
7
Explanation:
Testcase 1: Element at 5th index in the linked list is 657 (1-based indexing).

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: """index is the node which is to be displayed in output

  Node is defined as

class Node:

    def __init__(self, data):

		self.data = data

		self.next = None

# Linked List class contains a Node object

class LinkedList:

    def __init__(self):

        self.head = None

This is method only submission.

 You only need to complete below method.

"""

def getNth(head, k):

    # Code here

Solutions:
def getNth(head, k):
	pos = 1
	temp = head
	while temp:
		if pos == k:
			return temp.data
		pos += 1
		temp = temp.next


def getNth(head, k):
	count = 0
	while count != k - 1:
		count += 1
		head = head.next
	return head.data


def getNth(head, k):
	if k <= 0 or head is None:
		return -1
	curr = head
	for i in range(k - 1):
		curr = curr.next
	return curr.data


def getNth(head, k):
	curr = head
	curr_node = 0
	while curr:
		curr_node += 1
		if curr_node == k:
			return curr.data
		curr = curr.next
	return -1


def getNth(head, k):
	temp = head
	count = 1
	while temp is not None and count is not k:
		count += 1
		temp = temp.next
	return temp.data


def getNth(head, k):
	count = 0
	x = head.data
	while head:
		count += 1
		if count == k:
			x = head.data
		head = head.next
	return x


def getNth(head, k):
	table = []
	while k:
		table.append(head.data)
		head = head.next
		k -= 1
	return table[-1]


def getNth(head, k):
	cur = head
	cnt = 1
	while cur is not None:
		if cnt == k:
			return cur.data
		cnt += 1
		cur = cur.next


def getNth(head, k):
	c = 1
	while c != k:
		c += 1
		head = head.next
	return head.data


def getNth(head, k):
	h = head
	for i in range(k - 1):
		h = h.next
	return h.data


def getNth(head, k):
	dummy = head
	while k - 1 > 0:
		dummy = dummy.next
		k -= 1
	return dummy.data


def getNth(head, k):
	curr = head
	count = 1
	while curr:
		if count == k:
			return curr.data
		count += 1
		curr = curr.next


def getNth(head, k):
	for i in range(T):
		l = 0
		while head is not None:
			if l == k - 1:
				return head.data
			l += 1
			head = head.next


def getNth(head, k):
	temp = head
	count = 1
	while temp != None:
		if k == 1:
			return temp.data
		temp = temp.next
		count += 1
		if count == k:
			return temp.data


def getNth(head, k):
	ind = 1
	curr = head
	while curr:
		if ind == k:
			return curr.data
		curr = curr.next
		ind += 1


def getNth(head, k):
	temp = head
	for x in range(k - 1):
		if temp:
			temp = temp.next
	return temp.data


def getNth(head, k):
	next_node = head
	counter = 1
	while next_node:
		if counter == k:
			return next_node.data
		else:
			next_node = next_node.next
			counter += 1
	return -1


def getNth(head, k):
	temp = head
	while k - 1:
		temp = temp.next
		k = k - 1
	return temp.data


def getNth(head, k):
	c = 1
	curr = head
	while curr:
		if k == c:
			return curr.data
		curr = curr.next
		c += 1


def getNth(head, k):
	list = []
	pointer = head
	for i in range(1, k + 1):
		list.append(pointer.data)
		if i == k:
			return pointer.data
		pointer = pointer.next


def getNth(head, k):
	temp = head
	c = 0
	while temp != None:
		c += 1
		if c == k:
			return temp.data
		temp = temp.next


def getNth(head, k):
	if head == None:
		return head
	cur = head
	count = 1
	while count < k:
		cur = cur.next
		count += 1
	val = cur.data
	return val


def getNth(head, k):
	ptr = head
	while k - 1 > 0:
		k -= 1
		ptr = ptr.next
	return ptr.data


def getNth(head, k):
	out = 1
	while out != k:
		head = head.next
		out += 1
	return head.data


class Node:

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

class LinkedList:

	def __init__(self):
		self.head = None

def getNth(head, k):
	count = 1
	curr = head
	while curr != None:
		if count == k:
			return curr.data
		else:
			count += 1
			curr = curr.next


def getNth(head, k):
	n = head
	count = 1
	while n is not None:
		if count == k:
			return n.data
		else:
			n = n.next
			count += 1


def getNth(head, k):
	current = head
	count = 1
	while current is not None:
		if count == k:
			return current.data
		count += 1
		current = current.next
	return None


def getNth(head, k):
	if head is None:
		return
	c = 0
	ptr1 = head
	ptr2 = head
	while ptr1:
		c += 1
		ptr1 = ptr1.next
	i = 1
	if k <= c:
		while i < k:
			ptr2 = ptr2.next
			i += 1
		return ptr2.data


def getNth(head, k):
	temp = head
	cnt = 1
	if k == 1:
		return temp.data
	while temp != None and cnt < k:
		temp = temp.next
		cnt += 1
	if temp != None and cnt == k:
		return temp.data
	return -1


def getNth(head, k: int) -> int:
	if head is None or k < 1:
		return None
	if k == 1:
		return head.data
	return getNth(head.next, k - 1)


def getNth(head, k: int) -> int:
	current = head
	value = current.data
	i = 1
	while current.next is not None and i < k:
		current = current.next
		value = current.data
		i += 1
	if i != k:
		return None
	return value


def getNth(head, k):
	k -= 1
	index = k
	temp = head
	if index == 0 and temp:
		return temp.data
	while temp and index > 0:
		temp = temp.next
		index -= 1
	return temp.data


def getNth(head, k):
	for _ in range(k - 1):
		head = head.next
	return head.data


def getNth(head, k):
	current = head
	index = 1
	while current and index < k:
		current = current.next
		index += 1
	return current.data


def getNth(head, k):
	l = []
	while head:
		l.append(head.data)
		head = head.next
	return l[k - 1]


def getNth(head, k):
	if k == 1:
		return head.data
	curr = head
	for i in range(k - 1):
		curr = curr.next
	return curr.data


def getNth(head, k):
	count = 1
	while head:
		if count == k:
			return head.data
		else:
			count += 1
			head = head.next


def getNth(head, k):
	k -= 1
	cur = head
	while cur and k:
		cur = cur.next
		k -= 1
	return cur.data


def getNth(head, k):
	curr = head
	count = 1
	while curr and count < k:
		curr = curr.next
		count += 1
	return curr.data


def getNth(head, k):
	i = 1
	current = head
	while i < k:
		current = current.next
		i = i + 1
	return current.data


def getNth(head, k):
	i = 1
	while head:
		if i == k:
			return head.data
		i = i + 1
		head = head.next


def getNth(head, k):
	last = head
	index = 1
	while last:
		if index == k:
			return last.data
		else:
			last = last.next
			index += 1


def getNth(head, k):
	temp = head
	i = 0
	while i < k - 1:
		temp = temp.next
		i += 1
	return temp.data


def getNth(head, k):
	temp = head
	lemgth = 0
	temp1 = head
	for i in range(k - 1):
		temp = temp.next
	return temp.data


def getNth(head, k):
	temp = 1
	while head is not None:
		if temp == k:
			return head.data
		temp += 1
		head = head.next


def getNth(head, k):
	i = 1
	node = head
	if not node.next:
		return node.data
	while i < k:
		node = node.next
		i = i + 1
	return node.data


def getNth(head, k):
	ans = []
	while head is not None:
		ans.append(head.data)
		head = head.next
		if k <= len(ans):
			return ans[k - 1]
	return -1


def getNth(head, k):
	L = LinkedList()
	L.head = head
	for i in range(k - 1):
		L.head = L.head.next
	return L.head.data


def getNth(Head, k):
	head = Head
	index = 1
	while head != None:
		if index == k:
			return head.data
		head = head.next
		index += 1
	return None