This kata is about singly 
linked list.  A linked list is an ordered set of data elements, each containing a link to its successor (and sometimes its predecessor, known as a double linked list).  You are you to implement an algorithm to find the kth to last element.

For example given a linked list of:
a -> b -> c -> d

if k is the number one then d should be returned
if k is the number two then c should be returned
if k is the number three then b should be returned
if k is the number four then a should be returned
if k exceeds the size of the list then None returned



Special Note --> Node classes contain two fields; data and next.
And to access the head of the list, use head. e.g. linked_list.head

Source: codewars | Difficulty: EASY
Tags: Data structures

Starter code: def search_k_from_end(linked_list, k):
	

Solutions:
def search_k_from_end(linked_list, k):
	a = b = linked_list.head
	for __ in xrange(k - 1):
		b = b.next
		if not b:
			return None
	while b.next:
		(a, b) = (a.next, b.next)
	return a.data


def search_k_from_end(linked_list, k):
	head = linked_list.head
	vals = []
	while head:
		vals.append(head.data)
		head = head.__next__
	return vals[-k] if k <= len(vals) else None


def search_k_from_end(ll, k):

	def _loop(n):
		if not n:
			return (1, None)
		r = _loop(n.__next__)
		return (1 + r[0], r[1] if r[0] != k else n.data)
	return _loop(ll.head)[1]


def search_k_from_end(linked_list, k):
	l = [linked_list.head.data]
	n = linked_list.head.next
	while n:
		l.append(n.data)
		n = n.next
	return None if k > len(l) else l[-k]


def search_k_from_end(linked_list, k):

	def rec(node, x):
		if not node:
			return x
		n = rec(node.next, x)
		return n if type(n) != int else n - 1 if n else node
	res = rec(linked_list.head, k - 1)
	if type(res) != int:
		return res.data


def search_k_from_end(linked_list, k):
	head = linked_list.head
	count = 0
	while head != None:
		count += 1
		head = head.__next__
	head = linked_list.head
	if k > count:
		return None
	while count - k > 0:
		count -= 1
		head = head.__next__
	return head.data


def search_k_from_end(l, k):
	(head, li) = (l.head, [])
	while head:
		li.append(head.data)
		head = head.next
	return li[-k] if k <= len(li) else None


def search_k_from_end(linked_list, k):
	fast_index = 0
	slow = linked_list.head
	node = linked_list.head
	while fast_index < k:
		if node:
			node = node.next
			fast_index += 1
		else:
			return None
	while node:
		node = node.next
		slow = slow.next
	return slow.data


def search_k_from_end(ll, k):

	def to_list(n):
		return [n.data] if not n.next else [n.data] + to_list(n.next)
	l = list(reversed(to_list(ll.head)))
	return l[k - 1] if k <= len(l) else None


def search_k_from_end(l, k):
	(m, n) = (l.head, l.head)
	while k:
		if not n:
			return None
		n = n.__next__
		k -= 1
	while n:
		m = m.__next__
		n = n.__next__
	return m and m.data