Given a linked list, delete N nodes after skipping M nodes of a linked list until the last of the linked list.
Example:
Input:
2
8
2 1
9 1 3 5 9 4 10 1
6
6 1
1 2 3 4 5 6 
Output: 
9 1 5 9 10 1
1 2 3 4 5 6
Explanation:
Deleting one node after skipping the M nodes each time, we have list as 9-> 1-> 5-> 9-> 10-> 1.
Input:
The first line of input contains the number of test cases T. For each test case, the first line of input contains a number of elements in the linked list, and the next M and N respectively space-separated. The last line contains the elements of the linked list.
Output:
The function should not print any output to the stdin/console.
Your Task:
The task is to complete the function linkdelete() which should modify the linked list as required.
Constraints:
size of linked list <= 1000

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

Starter code:
# your task is to complete this Function

# Function shouldn't return anything



'''

class Node:

    # Constructor to initialize the node object

    def __init__(self, data):

        self.data = data

        self.next = None

'''

class Solution:

    def skipMdeleteN(self, head, M, N):

        # Code here



Solutions:
class Solution:

	def skipMdeleteN(self, head, M, N):
		temp = head
		prev = None
		i = 0
		while temp:
			if i != M:
				i += 1
				prev = temp
				temp = temp.next
			else:
				j = 0
				while temp and j != N:
					j += 1
					temp = temp.next
				prev.next = temp
				i = 0
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		h = head
		i = 1
		j = 0
		while head:
			if i == M:
				b = head.next
				while j != N and b != None:
					b = b.next
					j += 1
				head.next = b
				i = 0
				j = 0
			i += 1
			if head != None:
				head = head.next
		return h


class Solution:

	def skipMdeleteN(self, head, M, N):
		curr = head
		while curr:
			i = 0
			while curr and i < M - 1:
				curr = curr.next
				i += 1
			if not curr:
				break
			j = 0
			tmp = curr.next
			while tmp and j < N:
				tmp = tmp.next
				j += 1
			curr.next = tmp
			curr = curr.next
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		h = head
		for i in range(M - 1):
			h = h.next
			if h == None:
				break
		for i in range(N):
			if h == None or h.next == None:
				break
			h.next = h.next.next
		while h != None:
			for i in range(M):
				h = h.next
				if h == None:
					break
			for i in range(N):
				if h == None or h.next == None:
					break
				h.next = h.next.next
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		count = 1
		temp = head
		while temp != None:
			if count != M:
				count += 1
				temp = temp.next
			elif count == M:
				count = 1
				temp1 = temp
				for i in range(N):
					if temp1.next:
						temp1 = temp1.next
					else:
						temp.next = None
						return head
				if temp1.next:
					temp.next = temp1.next
					count = 0
				else:
					temp.next = None
					return head
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		if N == 0:
			return head
		tmp = head
		k = 1
		while tmp:
			if k == M:
				a = tmp
				for _ in range(N):
					if a.next:
						a = a.next
					else:
						tmp.next = None
						return head
				if a.next:
					tmp.next = a.next
					a.next = None
					k = 0
				else:
					tmp.next = None
					return head
			tmp = tmp.next
			k += 1
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		if not head:
			return
		it = head
		for i in range(M - 1):
			if not it:
				return
			it = it.next
		if not it:
			return
		MthNode = it
		it = MthNode.next
		for i in range(N):
			if not it:
				break
			temp = it.next
			del it
			it = temp
		MthNode.next = it
		self.skipMdeleteN(it, M, N)


class Solution:

	def skipMdeleteN(self, head, M, N):
		trav = head
		count = 0
		while trav:
			count += 1
			if count == M:
				skipper = trav.next
				skipCount = N
				while skipper and skipCount > 0:
					skipper = skipper.next
					skipCount -= 1
				trav.next = skipper
				count = 0
			trav = trav.next
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		curr_node = head
		while curr_node:
			for i in range(M - 1):
				if curr_node.next:
					curr_node = curr_node.next
				else:
					return head
			for i in range(N):
				if curr_node.next:
					curr_node.next = curr_node.next.next
				else:
					return head
			curr_node = curr_node.next
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		start = Node(0)
		start.next = head
		p1 = start
		while p1:
			(m, n) = (M, N)
			while m and p1:
				m -= 1
				p1 = p1.next
			p2 = p1
			while n and p2:
				p2 = p2.next
				n -= 1
			if p1:
				p1.next = p2.next if p2 else None
		return start.next


class Solution:

	def skipMdeleteN(self, head, M, N):
		curr = head
		while curr:
			for i in range(1, M):
				if curr is None:
					return
				curr = curr.next
			if curr is None:
				return
			t = curr.next
			for i in range(1, N + 1):
				if t is None:
					break
				t = t.next
			curr.next = t
			curr = t


class Solution:

	def skipMdeleteN(self, head, M, N):
		self.head = head
		self.m = M
		self.n = N
		temp = self.head
		while temp:
			i = 0
			while i < self.m - 1 and temp != None:
				temp = temp.next
				i += 1
			prev = temp
			if temp == None:
				break
			temp = temp.next
			i = 0
			while i < self.n and temp != None:
				temp = temp.next
				i += 1
			if prev != None:
				prev.next = temp


class Solution:

	def skipMdeleteN(self, head, M, N):
		if M == 0:
			return None
		tmp = head
		while head:
			m = M
			n = N
			while head and m - 1:
				head = head.next
				m -= 1
			while head and head.next and n:
				head.next = head.next.next
				n -= 1
			if head:
				head = head.next
		return tmp


class Solution:

	def skipMdeleteN(self, head, M, N):
		i = M
		j = N
		if N is 0:
			return head
		count = 0
		temp = head
		while temp:
			count += 1
			temp = temp.next
		temp1 = head
		while count > 1:
			while i > 1 and temp1:
				temp1 = temp1.next
				i = i - 1
				count = count - 1
			i = M
			if temp1 is None:
				return
			temp3 = temp1
			temp4 = temp1
			while j > 0 and temp3:
				temp3 = temp3.next
				count = count - 1
				j = j - 1
			if temp3:
				temp3_next = temp3.next
				temp1.next = temp3_next
				temp3.next = None
				temp3 = temp3_next
				temp1 = temp1.next
			elif j is not 0:
				temp4.next = None
				return
			j = N


class Solution:

	def skipMdeleteN(self, head, M, N):
		(temp, new_temp) = (head, head)
		while temp and new_temp:
			for i in range(M - 1):
				temp = temp.next
				if temp is None or temp.next is None:
					return
			new_temp = temp.next
			for i in range(N):
				new_temp = new_temp.next
				if new_temp is None:
					break
			temp.next = new_temp
			temp = temp.next


class Solution:

	def skipMdeleteN(self, head, M, N):
		n = head
		c = 1
		while n:
			if c < M:
				c += 1
				n = n.next
			elif c >= M:
				c = 0
				cc = 0
				nn = n
				while nn != None and cc <= N:
					nn = nn.next
					cc += 1
				if n.next:
					n.next = nn


class Solution:

	def skipMdeleteN(self, head, M, N):
		if M == 0:
			return None
		if N == 0:
			return head
		prev = None
		curr = head
		count = 1
		while curr != None:
			if count == M + 1:
				c2 = 0
				while curr != None and c2 < N:
					curr = curr.next
					c2 += 1
				prev.next = curr
				prev = curr
				if curr != None:
					curr = curr.next
				count = 2
			else:
				prev = curr
				curr = curr.next
				count += 1
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		if N == 0:
			return
		curr = head
		counter = 1
		do = 'yes'
		while curr != None:
			while counter != M and curr != None:
				curr = curr.next
				counter += 1
			prev = curr
			counter = 0
			while counter != N:
				if curr != None:
					curr = curr.next
				if curr == None:
					do = 'no'
					break
				counter += 1
			if do == 'yes':
				prev.next = curr.next
				curr = prev.next
			elif prev != None:
				prev.next = None
			counter = 1


class Solution:

	def skipMdeleteN(self, head, M, N):
		aux = head
		while aux:
			i = 0
			while i < M - 1 and aux:
				aux = aux.next
				i += 1
			if not aux:
				return
			next = aux
			i = 0
			while i < N and next.next:
				next = next.next
				i += 1
			aux.next = next.next
			aux = aux.next


class Solution:

	def skipMdeleteN(self, head, M, N):
		h = head
		if N == 0:
			return head
		k = 1
		while h:
			if k == M:
				a = h
				for i in range(N):
					if a.next:
						a = a.next
					else:
						h.next = None
						return head
				if a.next:
					h.next = a.next
					a.next = None
					k = 0
				else:
					h.next = None
					return head
			h = h.next
			k += 1
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		curr = head
		if N != 0:
			while curr:
				for i in range(M - 1):
					if curr.next is None:
						continue
					curr = curr.next
				if curr is None:
					break
				for i in range(N):
					if curr.next is None:
						continue
					temp = curr.next
					curr.next = temp.next
				curr = curr.next


class Solution:

	def skipMdeleteN(self, head, M, N):
		while head != None:
			temp = head
			i = M
			while i != 0 and head != None:
				temp = head
				head = head.next
				i = i - 1
			i = N
			while i != 0 and head != None:
				head = head.next
				i = i - 1


class Solution:

	def skipMdeleteN(self, head, M, N):
		if not head:
			return None
		MM = M - 1
		temp = head
		while MM and temp:
			temp = temp.next
			MM -= 1
		if MM or not temp:
			return head
		n_head = temp.next
		for i in range(N):
			if not n_head:
				break
			n_head = n_head.next
		temp.next = n_head
		self.skipMdeleteN(n_head, M, N)
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		start = head
		while start:
			count = M - 1
			count1 = N
			while count > 0 and start:
				start = start.next
				count -= 1
			if not start:
				break
			delete = Node(0)
			delete = start.next
			start.next = None
			while count1 > 0 and delete:
				delete = delete.next
				count1 -= 1
			if not delete:
				break
			start.next = delete
			start = delete


class Solution:

	def skipMdeleteN(self, head, M, N):
		l = self.length(head)
		if M > l:
			return head
		if N == 0:
			return head
		arr1 = []
		arr2 = []
		itr = head
		while itr:
			arr1.append(itr.data)
			itr = itr.next
		i = 0
		j = 0
		while i < len(arr1):
			if j < M:
				arr2.append(arr1[i])
				j += 1
				i += 1
			else:
				j = 0
				i += N
		if len(arr2) == 0:
			return None
		elif len(arr2) == 1:
			current = head
			current.next = None
			return
		else:
			current = head
			for i in range(1, len(arr2)):
				current.next = Node(arr2[i])
				current = current.next
			return

	def length(self, head):
		if head is None:
			return 0
		count = 0
		itr = head
		while itr:
			count += 1
			itr = itr.next
		return count


class Solution:

	def skipMdeleteN(self, head, M, N):
		ptr = head
		count = 1
		save = None
		delete = None
		if head is None:
			return None
		while ptr is not None:
			if count == M:
				save = ptr
			elif count == M + N + 1:
				delete = ptr
			if save is not None and delete is not None:
				save.next = delete
				save = None
				delete = None
				count = 1
			else:
				ptr = ptr.next
				count += 1
		if save is not None and count != 1:
			save.next = None
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		ptr1 = head
		ptr2 = head
		count = 1
		while ptr2.next:
			if count < M + N:
				ptr2 = ptr2.next
				if count < M:
					ptr1 = ptr1.next
			if count == M + N:
				ptr1.next = ptr2.next
				ptr2 = ptr2.next
				ptr1 = ptr2
			if count != M + N:
				count += 1
			elif count == M + N:
				count = 1
		ptr1.next = None
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		temp = head
		count = 0
		before = head
		while temp:
			count += 1
			if count % M == 0:
				ncount = N
				while ncount:
					ncount -= 1
					if temp.next is not None:
						temp = temp.next
				before.next = temp.next
				temp = before
			if temp is not None:
				temp = temp.next
				before = before.next
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		if not head:
			return None
		if not head.next:
			return head
		c = 1
		itr = head
		while itr:
			if c == M:
				temp_itr = itr
				rem_count = 0
				while temp_itr:
					if rem_count == N + 1:
						itr.next = temp_itr
						c = 0
						break
					else:
						temp_itr = temp_itr.next
						rem_count += 1
				if not temp_itr:
					itr.next = temp_itr
					break
			itr = itr.next
			c += 1
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		count = 0
		prev = None
		current = head
		while current.next:
			prev = current
			current = current.next
			count += 1
			if count % M == 0:
				x = N
				while x > 0:
					prev.next = current.next
					if current.next == None:
						break
					current = current.next
					count = 0
					x -= 1


class Solution:

	def skipMdeleteN(self, head, M, N):
		ptr = head
		while True:
			i = M
			while i - 1 and ptr:
				ptr = ptr.next
				i -= 1
			if ptr is None:
				return head
			j = N
			temp = ptr
			while j and temp:
				temp = temp.next
				j -= 1
			if temp is None:
				ptr.next = None
				return head
			ptr.next = temp.next
			ptr = ptr.next
		return head


def freeList(node):
	while node != None:
		next = node.next
		node = next
	return node

class Solution:

	def skipMdeleteN(self, head, M, N):
		ptr = head
		while ptr:
			for count in range(1, M):
				if ptr is None:
					return
				ptr = ptr.next
			if ptr is None:
				return
			ptr1 = ptr.next
			for count in range(1, N + 1):
				if ptr1 is None:
					break
				ptr1 = ptr1.next
			ptr.next = ptr1
			ptr = ptr1


class Solution:

	def skipMdeleteN(self, head, M, N):
		if head == None:
			return
		if N == 0:
			return head
		i = 1
		cur = head
		while cur != None:
			if i == M:
				a = cur
				for j in range(N):
					if a.next != None:
						a = a.next
					else:
						cur.next = None
						return head
				if a.next != None:
					cur.next = a.next
					a.next = None
					i = 0
				else:
					cur.next = None
					return head
			cur = cur.next
			i += 1
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		if head.next is None:
			return
		for _ in range(M - 1):
			head = head.next
			if head.next is None:
				return
		while True:
			temp = head
			for _ in range(N):
				temp = temp.next
				if temp.next is None:
					head.next = None
					return
			head.next = temp.next
			for _ in range(M):
				head = head.next
				if head.next is None:
					return


class Solution:

	def skipMdeleteN(self, head, M, N):
		countM = 0
		countN = 0
		curr = head
		prev = None
		while curr != None:
			if countM != M:
				prev = curr
				curr = curr.next
				countM += 1
			else:
				countM = 0
				while countN != N and curr != None:
					curr = curr.next
					countN += 1
				countN = 0
				if prev == None:
					head = curr
				else:
					prev.next = curr
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		if head == None:
			return head
		counter = 1
		p = head
		while p != None:
			if counter == M:
				temp = p
				follow = N
				while follow and p.next != None:
					p = p.next
					follow -= 1
				temp.next = p.next
				counter = 0
			counter += 1
			p = p.next
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		if head:
			c1 = 0
			c2 = 0
			temp = head
			prev = None
			while temp:
				if c1 != M:
					prev = temp
					temp = temp.next
					c1 += 1
				elif c2 != N:
					c2 += 1
					if temp:
						if temp.next:
							temp = temp.next
						else:
							prev.next = None
							return head
					else:
						prev.next = None
						return head
				else:
					c1 = 0
					c2 = 0
					prev.next = temp
			return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		skip = head
		while skip:
			for i in range(M - 1):
				if skip != None:
					skip = skip.next
				else:
					break
			if skip != None:
				dele = skip.next
			for i in range(N):
				if dele != None:
					dele = dele.next
				else:
					break
			if skip != None:
				skip.next = dele
				skip = dele


class Solution:

	def skipMdeleteN(self, head, M, N):
		dummy = Node(0)
		dummy.next = head
		first = dummy.next
		while first:
			for i in range(1, M):
				if first:
					first = first.next
				else:
					break
			if first:
				second = first.next
			else:
				break
			for i in range(N):
				if second:
					second = second.next
				else:
					break
			first.next = second
			first = second
		return dummy.next


class Solution:

	def skipMdeleteN(self, head, M, N):
		dummy = Node(-100)
		lg = dummy
		fast = head
		while fast:
			slow = pf = fast
			steps = 0
			while fast and steps < M:
				steps += 1
				pf = fast
				fast = fast.next
			lg.next = slow
			lg = pf
			steps = 0
			while fast and steps < N:
				fast = fast.next
				steps += 1
		lg.next = None
		return dummy.next


class Solution:

	def skipMdeleteN(self, head, M, N):
		curr_node = head
		while curr_node != None:
			curr1 = 1
			while curr1 < M:
				if curr_node == None:
					return
				curr_node = curr_node.next
				curr1 += 1
			if curr_node == None:
				return
			curr2 = 0
			t = curr_node.next
			while curr2 < N:
				if t == None:
					break
				t = t.next
				curr2 += 1
			curr_node.next = t
			curr_node = t


class Solution:

	def remove(self, temp, N):
		for i in range(0, N):
			temp = temp.next
		return temp

	def skipMdeleteN(self, head, M, N):
		curr = head
		while curr:
			for count in range(1, M):
				if curr is None:
					return
				curr = curr.next
			if curr is None:
				return
			t = curr.next
			for count in range(1, N + 1):
				if t is None:
					break
				t = t.next
			curr.next = t
			curr = t


class Solution:

	def skipMdeleteN(self, head, M, N):
		dummy = head
		count = 1
		c = N
		while dummy and dummy.next:
			if count == M:
				while c != 0 and dummy and dummy.next:
					dummy.next = dummy.next.next
					c -= 1
				c = N
				count = 0
			else:
				dummy = dummy.next
				count += 1
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		curr = head
		while curr and curr.next:
			for i in range(M - 1):
				if curr == None:
					break
				curr = curr.next
			if curr == None:
				break
			temp = curr.next
			for i in range(N):
				if temp == None:
					break
				temp = temp.next
			curr.next = temp
			curr = curr.next
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		cn = 1
		curr = head
		while curr:
			if cn == M:
				k = 0
				curr1 = curr
				while curr1 and k <= N:
					curr1 = curr1.next
					k += 1
				cn = 0
				curr.next = curr1
			curr = curr.next
			cn += 1
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):

		def move(head, m):
			tmp = head
			while tmp and m != 1:
				tmp = tmp.next
				m -= 1
			return tmp
		tmp = head
		while tmp:
			tmp = move(tmp, M)
			if tmp == None:
				break
			tmp2 = move(tmp, N + 1)
			if tmp2 == None:
				tmp.next = tmp2
				break
			tmp.next = tmp2.next
			tmp = tmp.next


class Solution:

	def skipMdeleteN(self, head, M, N):
		l = list()
		temp = head
		while temp != None:
			l.append(temp.data)
			temp = temp.next
		length = len(l)
		i = 0
		count = 0
		l2 = list()
		while i < length:
			if count < M:
				l2.append(l[i])
				i = i + 1
				count = count + 1
			else:
				i = i + N
				count = 0
		temp = head
		length = len(l2) - 1
		i = 0
		prev = head
		for i in range(len(l2)):
			temp.data = l2[i]
			length = length - 1
			prev = temp
			temp = temp.next
		prev.next = None
		temp = None
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		temp = head
		c = 1
		while temp and temp.next:
			if c % M == 0 and temp and temp.next:
				for i in range(N):
					if temp.next:
						temp.next = temp.next.next
					else:
						break
			c += 1
			temp = temp.next
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		nxt = curr = head
		M = M - 1
		p = 0
		sk = 0
		N = N + 1
		while nxt:
			if nxt != None and p < M:
				nxt = nxt.next
				p = p + 1
				curr = nxt
				continue
			if nxt != None and sk < N:
				nxt = nxt.next
				sk = sk + 1
				continue
			curr.next = nxt
			curr = nxt
			p = 0
			sk = 0
		if curr != None:
			curr.next = None
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		if N == 0:
			return head
		snodes = M
		dnodes = N
		scount = 0
		dcount = 0
		cur = head
		prenode = None
		while cur != None:
			if scount == snodes:
				scount = 0
				while cur != None:
					dcount = dcount + 1
					if dcount == dnodes:
						prenode.next = cur.next
						cur = cur.next
						dcount = 0
						break
					else:
						cur = cur.next
						if cur == None:
							prenode.next = None
			else:
				prenode = cur
				cur = cur.next
				scount = scount + 1


class Solution:

	def skipMdeleteN(self, head, M, N):
		currentNode = head
		while currentNode:
			i = 1
			while i <= M - 1 and currentNode != None:
				currentNode = currentNode.next
				i = i + 1
			if currentNode == None:
				break
			j = 1
			NodeToComeNext = currentNode.next
			while j <= N and NodeToComeNext != None:
				NodeToComeNext = NodeToComeNext.next
				j = j + 1
			currentNode.next = NodeToComeNext
			currentNode = currentNode.next


class Solution:

	def skipMdeleteN(self, head, m, n):
		curr = head
		while curr is not None:
			pos = m - 1
			while pos:
				if curr is None:
					break
				curr = curr.next
				pos -= 1
			skip = n
			while skip:
				if curr is None or curr.next is None:
					break
				else:
					curr.next = curr.next.next
					skip -= 1
			if curr is not None:
				curr = curr.next


class Solution:

	def skipMdeleteN(self, head, M, N):
		temp = head
		prev = temp
		while temp is not None:
			for i in range(M):
				if temp is None:
					return head
				prev = temp
				temp = temp.next
			for j in range(N):
				if temp is None:
					break
				temp = temp.next
			prev.next = temp
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		cur = head
		while cur:
			i = 1
			while cur and i < M:
				i += 1
				cur = cur.next
			if not cur:
				break
			j = 1
			temp = cur.next
			while temp and j <= N:
				j += 1
				temp = temp.next
			cur.next = temp
			cur = cur.next
		return head


class Solution:

	def skipMdeleteN(self, head, M, N):
		if N == 0:
			return head

		def removeNodes(root):
			temp = root
			for i in range(N - 1):
				if not temp:
					break
				temp = temp.next
			if not temp:
				return None
			return temp.next
		node = head
		while node:
			for i in range(M - 1):
				node = node.next
				if not node:
					break
			if not node:
				break
			node.next = removeNodes(node.next)
			node = node.next
		return head