Given a singly linked list of size N. The task is to left-shift the linked list by k nodes, where k is a given positive integer smaller than or equal to length of the linked list. 
Example 1:
Input:
N = 5
value[] = {2, 4, 7, 8, 9}
k = 3
Output: 8 9 2 4 7
Explanation:
Rotate 1: 4 -> 7 -> 8 -> 9 -> 2
Rotate 2: 7 -> 8 -> 9 -> 2 -> 4
Rotate 3: 8 -> 9 -> 2 -> 4 -> 7
Example 2:
Input:
N = 8
value[] = {1, 2, 3, 4, 5, 6, 7, 8}
k = 4
Output: 5 6 7 8 1 2 3 4
Your Task:
You don't need to read input or print anything. Your task is to complete the function rotate() which takes a head reference as the first argument and k as the second argument, and returns the head of the rotated linked list.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{3}
1 <= k <= N

Source: geeksforgeeks | Difficulty: MEDIUM
Tags: Data structures

Starter code: # Your task is to complete this function



'''



class Node:

    def __init__(self, data):

        self.data = data

        self.next = None



'''





class Solution:

    

    #Function to rotate a linked list.

    def rotate(self, head, k):

        # code here



Solutions:
class Solution:

	def rotate(self, head, k):
		if head == None or k == 0:
			return head
		prev = head
		while prev.next:
			prev = prev.next
		for i in range(k):
			prev.next = head
			head = head.next
			prev = prev.next
			prev.next = None
		return head


class Solution:

	def rotate(self, head, k):
		temp = head
		while temp.next:
			temp = temp.next
		temp.next = head
		while k > 0:
			temp = temp.next
			k -= 1
		head = temp.next
		temp.next = None
		return head


class Solution:

	def rotate(self, head, k):
		if head is None:
			return None
		cur = head
		length = 1
		while cur.next:
			length += 1
			cur = cur.next
		cur.next = head
		k = k % length
		while k > 0:
			cur = cur.next
			k -= 1
		head = cur.next
		cur.next = None
		return head


class Solution:

	def rotate(self, head, k):
		t = head
		c = 0
		while t:
			c = c + 1
			t = t.next
		if c == k:
			return head
		z = head.next
		temp = head
		b = k
		while temp and b > 1:
			z = z.next
			temp = temp.next
			b = b - 1
		temp.next = None
		s = z
		k = s
		while k.next:
			k = k.next
		k.next = head
		return s


class Solution:

	def rotate(self, head, k):
		x = []
		ptr = head
		while ptr != None:
			x.append(ptr.data)
			ptr = ptr.next
		x = x[k:] + x[:k]
		ptr = head
		for i in x:
			ptr.data = i
			ptr = ptr.next
		return head


class Solution:

	def rotate(self, head, k):
		(st, c) = (None, 0)
		temp = head
		pre = None
		while temp:
			pre = temp
			c += 1
			if c == k:
				st = temp.next
				temp.next = None
				temp = st
			else:
				temp = temp.next
		if not st:
			return head
		pre.next = head
		return st


class Solution:

	def rotate(self, head, k):
		c = head
		arr = []

		def shift(arr, k):

			def swap(arr, l, r):
				while l < r:
					(arr[l], arr[r]) = (arr[r], arr[l])
					l += 1
					r -= 1
			k = k % len(arr)
			swap(arr, 0, len(arr) - 1)
			swap(arr, 0, len(arr) - k - 1)
			swap(arr, len(arr) - k, len(arr) - 1)
			return arr
		headd = head
		while headd:
			arr.append(headd.data)
			headd = headd.next
		c = shift(arr, k)
		dummy = Node(0)
		tail = dummy
		for i in c:
			tail.next = Node(i)
			tail = tail.next
		return dummy.next


class Solution:

	def rotate(self, head, k):
		if head is None or head.next is None or k == 0:
			return head
		len = 1
		current = head
		while len < k and current is not None:
			current = current.next
			len += 1
		if current is None:
			return head
		kthNode = current
		while current.next is not None:
			current = current.next
		current.next = head
		head = kthNode.next
		kthNode.next = None
		return head


class Solution:

	def rotate(self, head, k):
		if k == 0:
			return head
		h = head
		h1 = head
		while h.next:
			h = h.next
		h.next = head
		while k != 1:
			h1 = h1.next
			k = k - 1
		head = h1.next
		h1.next = None
		return head


class Solution:

	def rotate(self, head, k):
		temp = head
		l = 0
		while temp != None:
			l += 1
			temp = temp.next
		if l == k:
			return head
		temp = head
		while temp.next != None and k > 1:
			temp = temp.next
			k -= 1
		rem = temp.next
		temp.next = None
		temp = rem
		while temp.next != None:
			temp = temp.next
		temp.next = head
		head = rem
		return head


class Solution:

	def rotate(self, head, k):
		temp = head
		while temp.next != None:
			temp = temp.next
		tail = temp
		for i in range(0, k):
			temp1 = head
			head = head.next
			tail.next = temp1
			tail = temp1
			tail.next = None
		return head


class Solution:

	def rotate(self, head, k):
		temp = head
		while temp.next:
			temp = temp.next
		for _ in range(k):
			temp_head = head.next
			temp.next = head
			head.next = None
			head = temp_head
			temp = temp.next
		return head


class Solution:

	def rotate(self, head, k):

		def Length(head):
			length = 0
			while head:
				length += 1
				head = head.next
			return length
		ptr = head
		prev = None
		prev_head = head
		c = 0
		n = Length(head)
		if k >= n:
			k = k % n
		while c < k:
			prev = ptr
			ptr = ptr.next
			c += 1
		head = ptr
		if k != 0:
			prev.next = None
			while ptr.next:
				ptr = ptr.next
			ptr.next = prev_head
		return head


class Solution:

	def rotate(self, head, k):
		kth = head
		while k > 1:
			kth = kth.next
			k -= 1
		tail = head
		while tail.next:
			tail = tail.next
		temp = kth.next
		if not temp:
			return head
		else:
			kth.next = None
			tail.next = head
			head = temp
			return head


class Solution:

	def rotate(self, head, k):
		x = []
		while head:
			x.append(head.data)
			head = head.next
		x = x[k:] + x[0:k]
		head = Node(x[0])
		cur = head
		for i in range(1, len(x)):
			cur.next = Node(x[i])
			cur = cur.next
		return head


class Solution:

	def rotate(self, head, k):
		r = head
		for i in range(k - 1):
			r = r.next
			if r == None:
				r = head
		if r.next == None:
			return head
		a = r.next
		r.next = None
		ans = a
		while a.next != None:
			a = a.next
		a.next = head
		return ans


class Solution:

	def rotate(self, head, k):
		lst = []
		temp = head
		while temp:
			lst.append(temp.data)
			temp = temp.next
		if lst:
			k = k % len(lst)
		f = lst[k:] + lst[:k]
		nn = Node(0)
		current = nn
		for i in f:
			current.next = Node(i)
			current = current.next
		return nn.next


class Solution:

	def rotate(self, head, k):
		if not head:
			return head
		tail = head
		length = 1
		while length < k:
			tail = tail.next
			length += 1
		curr = tail
		while tail.next:
			tail = tail.next
		tail.next = head
		newhead = curr.next
		curr.next = None
		return newhead


class Solution:

	def rotate(self, head, k):
		a = b = Node(0)
		c = d = Node(0)
		i = 0
		while head:
			i = i + 1
			if i > k:
				b.next = head
				b = b.next
				head = head.next
			else:
				d.next = head
				d = d.next
				head = head.next
		d.next = None
		b.next = c.next
		return a.next


class Solution:

	def rotate(self, head, k):
		tmp = cn = head
		n = k
		while k:
			cn = cn.next
			k -= 1
		if cn is not None:
			head = cn
			while cn.next:
				cn = cn.next
			while n:
				cn.next = tmp
				tmp = tmp.next
				cn = cn.next
				n -= 1
			cn.next = None
		return head


class Solution:

	def rotate(self, head, k):
		if head is None:
			return head
		if head.next is None:
			return head
		len = 0
		temp = head
		while temp:
			len += 1
			temp = temp.next
		k = k % len
		if k == 0:
			return head
		temp = head
		for i in range(k - 1):
			temp = temp.next
		head2 = temp.next
		temp.next = None
		temp2 = head2
		while temp2.next:
			temp2 = temp2.next
		temp2.next = head
		return head2


class Solution:

	def rotate(self, head, k):
		temp = head
		i = 1
		while i < k:
			temp = temp.next
			i += 1
		next = temp.next
		temp.next = None
		temp = next
		try:
			while next.next != None:
				next = next.next
			next.next = head
			head = temp
		except AttributeError:
			return head
		return head


class Solution:

	def rotate(self, head, k):
		prev = None
		curr = head
		for i in range(k):
			prev = curr
			curr = curr.next
		if curr is None:
			return head
		prev.next = None
		start = curr
		while curr.next is not None:
			curr = curr.next
		curr.next = head
		return start


class Solution:

	def rotate(self, head, k):
		x = []
		while head != None:
			x.append(head.data)
			head = head.next
		a = x[k:]
		b = x[0:k]
		c = a + b
		for i in c:
			print(i, end=' ')


class Solution:

	def rotate(self, head, k):
		prev = head
		cur = head
		n = Node(0)
		n.next = head
		c = prev.next
		while cur.next:
			cur = cur.next
		i = Node(0)
		cur.next = i
		while k:
			cur.next = prev
			prev.next = i
			n.next = c
			prev = n.next
			c = prev.next
			cur = cur.next
			k -= 1
		cur.next = None
		return n.next


class Solution:

	def rotate(self, head, k):
		if not head or head.next is None:
			return head
		temp = head.next
		for i in range(k):
			while temp.next is not None:
				temp = temp.next
			temp.next = head
			cur = head.next
			head.next = None
			head = cur
		return head


class Solution:

	def rotate(self, head, k):
		curr = head
		while curr.next != None:
			curr = curr.next
		curr.next = head
		curr = head
		for i in range(k - 1):
			curr = curr.next
		newHead = curr.next
		curr.next = None
		return newHead


class Solution:

	def rotate(self, head, k):
		curr = head
		curr1 = head
		while curr.next:
			curr = curr.next
		curr.next = head
		prev = curr1
		while k > 0:
			prev = curr1
			curr1 = curr1.next
			k = k - 1
		prev.next = None
		return curr1


class Solution:

	def rotate(self, head, k):
		last = head
		temp = head
		if head == None or k == 0:
			return head
		while last.next != None:
			last = last.next
		while k:
			head = head.next
			temp.next = None
			last.next = temp
			last = temp
			temp = head
			k -= 1
		return head


class Solution:

	def rotate(self, head, k):
		n = 0
		tmp = head
		while tmp:
			tmp = tmp.next
			n += 1
		k = k % n
		if k == 0:
			return head
		tmp = head
		t = 1
		while t < k:
			tmp = tmp.next
			t += 1
		ret = tmp.next
		o = ret
		tmp.next = None
		while ret.next:
			ret = ret.next
		ret.next = head
		return o


class Solution:

	def rotate(self, head, k):
		pre = None
		next = head
		for i in range(k):
			pre = next
			next = next.next
		if next is None:
			return head
		pre.next = None
		pre = head
		head = next
		while next.next:
			next = next.next
		next.next = pre
		return head


class Solution:

	def rotate(self, head, k):
		p1 = head
		while k > 1:
			head = head.next
			k -= 1
		p2 = head
		p3 = p2.next
		if p3 is None:
			return p1
		temp = p3
		p2.next = None
		while p3.next is not None:
			p3 = p3.next
		p3.next = p1
		return temp


class Solution:

	def rotate(self, start, k):
		if k == 0:
			return start
		temp = start
		while temp and k != 1:
			temp = temp.next
			k -= 1
		forw = temp.next
		new_start = forw
		temp.next = None
		if forw is None:
			return start
		temp = forw
		while temp.next:
			temp = temp.next
		temp.next = start
		start = new_start
		return start


class Solution:

	def rotate(self, head, k):
		node = target_node = head
		tmp = [node.data]
		for i in range(k):
			if not target_node.next:
				return head
			target_node = target_node.next
			tmp.append(target_node.data)
		while target_node.next:
			node.data = target_node.data
			node = node.next
			target_node = target_node.next
		node.data = target_node.data
		for i in range(k):
			node = node.next
			node.data = tmp[i]
		return head


class Solution:

	def rotate(self, start, k):
		temp = start
		while temp.next:
			temp = temp.next
		while k > 0:
			prev = start
			temp.next = prev
			temp = temp.next
			start = start.next
			k -= 1
		temp.next = None
		return start


class Solution:

	def rotate(self, head, k):
		n = 1
		tem = head
		while tem.next != None:
			n += 1
			tem = tem.next
		if n == k:
			return head
		else:
			temp1 = head
			temp2 = head
			m = 1
			while k != m:
				temp2 = temp2.next
				m += 1
			head = temp2.next
			temp2.next = None
			temp3 = head
			while temp3.next != None:
				temp3 = temp3.next
			temp3.next = temp1
			return head


class Solution:

	def rotate(self, head, k):
		temp1 = head
		while temp1.next != None:
			temp1 = temp1.next
		temp2 = head
		while k:
			head = temp2.next
			temp1.next = temp2
			temp1 = temp2
			temp2 = head
			k = k - 1
		temp1.next = None
		return head


class Solution:

	def rotate(self, head, k):
		cur = head
		for i in range(k - 1):
			cur = cur.next
		new_head = cur.next
		if new_head is None:
			return head
		cur.next = None
		cur = new_head
		while cur.next:
			cur = cur.next
		cur.next = head
		return new_head


class Solution:

	def rotate(self, head, k):
		temp = head
		while temp != None and k > 1:
			temp = temp.next
			k -= 1
		if temp.next == None:
			return head
		new_head = temp.next
		temp.next = None
		temp = new_head
		while temp.next != None:
			temp = temp.next
		temp.next = head
		return new_head


class Solution:

	def rotate(self, h, k):
		n = h
		while n.next:
			n = n.next
		for i in range(k):
			n.next = h
			n = n.next
			h = h.next
			n.next = None
		return h


class Solution:

	def rotate(self, head, k):
		if not head or k == 0:
			return head
		length = 0
		current = head
		while current:
			length += 1
			current = current.next
		k = k % length
		if k == 0:
			return head
		current = head
		for i in range(k - 1):
			current = current.next
		new_head = current.next
		current.next = None
		current = new_head
		while current.next:
			current = current.next
		current.next = head
		return new_head


class Solution:

	def rotate(self, head, k):
		a = head
		ptr1 = ptr = Node(1)
		ptr2 = ptr3 = Node(1)
		while a:
			if k > 0:
				ptr.next = a
				ptr = ptr.next
				k = k - 1
			else:
				ptr3.next = a
				ptr3 = ptr3.next
			a = a.next
		ptr3.next = ptr1.next
		ptr.next = None
		return ptr2.next


class Solution:

	def rotate(self, head, k):
		a = head
		ptr1 = ptr = Node(1)
		ptr2 = ptr3 = Node(1)
		c = 0
		l = []
		l2 = []
		while a:
			if c < k:
				l.append(a.data)
			else:
				l2.append(a.data)
			a = a.next
			c += 1
		l = l2 + l
		x = 0
		b = head
		while b:
			b.data = l[x]
			x += 1
			b = b.next
		return head


class Solution:

	def rotate(self, head, k):
		if head == None or head.next == None:
			return head
		end = head
		while end.next != None:
			end = end.next
		end.next = head
		temp = head
		prev = None
		n = 0
		while n < k:
			prev = temp
			temp = temp.next
			n = n + 1
		prev.next = None
		return temp


class Solution:

	def rotate(self, head1, k):
		temp1 = head1
		co = 1
		while temp1.next is not None:
			co += 1
			temp1 = temp1.next
		if co == k:
			return head1
		c = 1
		l3 = LinkedList()
		head = None
		temp = head1
		while c <= k:
			l3.insert(temp.data)
			temp = temp.next
			c += 1
		i = 1
		while i <= k:
			head1 = head1.next
			i += 1
		while temp.next is not None:
			temp = temp.next
		temp.next = l3.head
		return head1


class Solution:

	def rotate(self, head, k):
		arr = []
		temp = head
		while temp:
			arr.append(temp.data)
			temp = temp.next
		res = []
		for i in range(k, len(arr)):
			res.append(arr[i])
		for i in range(0, k):
			res.append(arr[i])
		head = Node(res[0])
		t = head
		for i in range(1, len(res)):
			x = Node(res[i])
			head.next = x
			head = head.next
		return t


class Solution:

	def rotate(self, head, k):
		tail = head
		while tail.next != None:
			tail = tail.next
		for i in range(k):
			t = Node(head.data)
			head = head.next
			tail.next = t
			tail = t
		return head


class Solution:

	def rotate(self, head, k):
		if head == None:
			return
		ptr = head
		while ptr.next != None:
			ptr = ptr.next
		for i in range(k):
			ptr.next = head
			ptr = ptr.next
			head = head.next
		ptr.next = None
		return head


class Solution:

	def rotate(self, head, k):
		if head == None:
			return None
		size = 1
		curr = head
		while curr.next:
			curr = curr.next
			size += 1
		curr.next = head
		k = k % size
		while k > 0:
			curr = curr.next
			k -= 1
		new_head = curr.next
		curr.next = None
		return new_head


class Solution:

	def rotate(self, head, k):
		temp = head
		n = 0
		while temp:
			temp = temp.next
			n += 1
		if k == n:
			return head
		temp = head
		while k != 1:
			temp = temp.next
			k -= 1
		new = temp.next
		temp.next = None
		temp = new
		while temp and temp.next:
			temp = temp.next
		temp.next = head
		return new


class Node:

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

class Solution:

	def rotate(self, head, k):
		if k == 0:
			return head
		tail = head
		length = 1
		while tail.next:
			length += 1
			tail = tail.next
		k = k % length
		if k == 0:
			return head
		tail.next = head
		for _ in range(k):
			tail = tail.next
		head = tail.next
		tail.next = None
		return head


class Solution:

	def rotate(self, head, k):
		res = []
		while head:
			res.append(head.data)
			head = head.next
		a = len(res)
		b = res[k:a] + res[0:k]
		curr = dummy = Node(0)
		for i in b:
			curr.next = Node(i)
			curr = curr.next
		return dummy.next


class Solution:

	def rotate(self, head, k):
		lenLL = self.getSize(head)
		k = k % lenLL
		if k == 0:
			return head
		curr = head
		for i in range(k):
			prev = curr
			curr = curr.next
		prev.next = None
		new_head = curr
		while curr.next is not None:
			curr = curr.next
		curr.next = head
		return new_head

	def getSize(self, head):
		size = 0
		while head is not None:
			size += 1
			head = head.next
		return size


class Solution:

	def rotate(self, head, k):
		p = head
		h = head
		c = 0
		l = 0
		q = head
		while c < k:
			c += 1
			p = p.next
		head = p
		if p == None:
			return h
		while p.next:
			l += 1
			p = p.next
		p.next = q
		while k:
			p = p.next
			k -= 1
		p.next = None
		return head


class Solution:

	def rotate(self, head, k):
		l = []
		t = head
		while t != None:
			l.append(t.data)
			t = t.next
		for i in range(k, len(l)):
			print(l[i], end=' ')
		for i in range(k):
			print(l[i], end=' ')


class Solution:

	def rotate(self, head, k):
		temp = head
		count = 0
		while temp:
			count += 1
			temp = temp.next
		if count == k:
			return head
		temp = head
		head2 = head
		count = 0
		while temp:
			count += 1
			if count == k:
				head2 = temp.next
				temp.next = None
				break
			temp = temp.next
		temp = head2
		while temp.next:
			temp = temp.next
		temp.next = head
		return head2


class Solution:

	def rotate(self, head, k):
		a = head
		p = []
		while a is not None:
			p.append(a.data)
			a = a.next
		list1 = p[k:] + p[:k]
		head1 = None
		m = None
		for i in list1:
			q = Node(i)
			if head1 is None:
				head1 = q
				m = head1
			else:
				head1.next = q
				head1 = head1.next
		return m


class Solution:

	def rotate(self, head, k):
		if k == 0:
			return
		current = head
		count = 1
		while count < k and current != None:
			current = current.next
			count += 1
		if current == None:
			return
		Nthnode = current
		while current.next != None:
			current = current.next
		current.next = head
		head = Nthnode.next
		Nthnode.next = None
		return head


class Solution:

	def rotate(self, head, k):
		ans = []
		while head:
			ans.append(head.data)
			head = head.next
		res = ans[k:] + ans[:k]
		a = Node(0)
		temp = a
		for i in res:
			temp.next = Node(i)
			temp = temp.next
		return a.next


class Solution:

	def rotate(self, head, k):
		(ctr, start, temp, l, s) = (1, head, head, 0, head)
		while ctr != k:
			head = head.next
			ctr += 1
		last = head
		beg = head.next
		while temp.next:
			temp = temp.next
			l += 1
		if l == k - 1:
			return s
		temp.next = start
		last.next = None
		return beg


class Solution:

	def rotate(self, head, k):

		def reverse(head):
			prev = None
			while head:
				temp = head.next
				head.next = prev
				prev = head
				head = temp
			return prev
		temp = head
		c = 1
		while True:
			if c == k:
				break
			temp = temp.next
			c += 1
		bed = temp.next
		temp.next = None
		node2 = reverse(bed)
		node1 = reverse(head)
		pet = node1
		while pet:
			pre = pet
			pet = pet.next
		pre.next = node2
		result = reverse(node1)
		return result


class Solution:

	def reverse(self, head):
		if head is None or head.next is None:
			return head
		pre = None
		cur = head
		while cur is not None:
			t = cur.next
			cur.next = pre
			pre = cur
			cur = t
		return pre

	def length(self, head):
		c = 0
		while head is not None:
			c += 1
			head = head.next
		return c

	def rotate(self, head, k):
		if head is None or head.next is None:
			return head
		l = self.length(head)
		if l == k:
			return head
		k = k % l
		t = self.reverse(head)
		d = l - k
		cur = t
		c = 0
		pre = None
		while c < d:
			c += 1
			pre = cur
			cur = cur.next
		pre.next = None
		te = self.reverse(t)
		t1 = self.reverse(cur)
		t.next = t1
		return te


class Solution:

	def rotate(self, head, k):
		itr = head
		l = []
		while itr:
			l.append(itr.data)
			itr = itr.next
		for i in range(k):
			l = l[1:] + l[0:1]
		head = Node(l[0])
		t = head
		for i in range(1, len(l)):
			x = Node(l[i])
			head.next = x
			head = head.next
		return t


class Solution:

	def rotate(self, head, k):
		prev = Node(0)
		prev = None
		curr = head
		tail = head
		le = 1
		while tail.next:
			tail = tail.next
			le += 1
		if le == k:
			return head
		for i in range(k):
			prev = curr
			curr = curr.next
		prev.next = None
		tail.next = head
		return curr


class Solution:

	def rotate(self, head, k):
		self.head = head
		self.k = k
		temp = prev = self.head
		i = 1
		flag = 0
		if temp is not None:
			while temp.next != None:
				if i == self.k:
					self.head = temp.next
					temp.next = None
					flag = 1
					break
				i += 1
				temp = temp.next
			if flag == 1:
				temp = self.head
				while temp.next != None:
					temp = temp.next
				temp.next = prev
		return self.head


class Solution:

	def rotate(self, head, k):
		c = 0
		start = head
		while c < k:
			c += 1
			if c != k:
				start = start.next
		if start.next == None:
			return head
		head2 = start.next
		start.next = None
		start = head2
		while start.next != None:
			start = start.next
		start.next = head
		return head2


class Solution:

	def rotate(self, head, k):
		i = 1
		curr = head
		while i != k:
			curr = curr.next
			i += 1
		if curr.next:
			p = curr.next
			r = curr.next
		else:
			p = 0
			r = head
		if p:
			while p.next:
				p = p.next
			p.next = head
		curr.next = None
		return r


class Solution:

	def rotate(self, head, k):
		tmp = head
		while head and k - 1:
			head = head.next
			k -= 1
		temp = None
		if head and head.next:
			temp = head.next
			head.next = None
		else:
			return tmp
		ttmp = temp
		while ttmp and ttmp.next:
			ttmp = ttmp.next
		if ttmp:
			ttmp.next = tmp
		return temp


class Solution:

	def rotate(self, head, k):
		root = head
		for i in range(k):
			while head:
				if head.next == None:
					break
				head = head.next
			head.next = root
			temp = root.next
			root.next = None
			root = temp
		while root:
			print(root.data, end=' ')
			root = root.next


class Solution:

	def rotate(self, head, k):
		temp = head
		start = head
		mid = head
		l = 0
		while temp:
			last = temp
			temp = temp.next
			l += 1
		if k == l:
			return head
		for _ in range(k - 1):
			mid = mid.next
		head = mid.next
		mid.next = None
		last.next = start
		return head


class Solution:

	def rotate(self, head, k):
		curr = head
		for i in range(k - 1):
			curr = curr.next
		tail = head
		len = 1
		while tail.next:
			tail = tail.next
			len += 1
		if k == len:
			return head
		temp = curr.next
		curr.next = None
		tail.next = head
		return temp


class Solution:

	def rotate(self, head, k):
		fast = head.next
		slow = head
		temp = head
		count = 1
		while count < k:
			count += 1
			slow = slow.next
			fast = fast.next
		if fast is None:
			return head
		slow.next = None
		head = fast
		while fast is not None and fast.next is not None:
			fast = fast.next
		fast.next = temp
		return head


class Solution:

	def rotate(self, head, k):
		temp = head
		while temp.next:
			temp = temp.next
		for i in range(k):
			temp2 = head.next
			head.next = None
			temp.next = head
			head = temp2
			temp = temp.next
		return head


class Solution:

	def rotate(self, head, k):
		if k is 0:
			return head
		temp = head
		while temp.next:
			temp = temp.next
		if temp:
			temp.next = head
		counter = head
		prev = None
		while k:
			prev = counter
			counter = counter.next
			k -= 1
		prev.next = None
		return counter


class Solution:

	def rotate(self, head, k):
		i = 0
		temp = head
		while temp:
			i += 1
			if i == k:
				head1 = temp.next
				temp.next = None
				break
			temp = temp.next
		if head1 is None:
			return head
		temr = head1
		while temr.next:
			temr = temr.next
		temr.next = head
		return head1