You are given an array nodes. It contains 7 integers, which represents the value of nodes of the binary tree in level order traversal. You are also given a root of the tree which has a value equal to nodes[0].
Your task to construct a binary tree by creating nodes for the remaining 6 nodes.
Example:
Input: 
nodes = [1 2 3 4 5 6 7]
Output: 
         1
       /   \
     2       3
   /  \     /  \
   4  5    6   7
Explanation: 
The 7 node binary tree is represented above.
Your Task:
Complete the function void create_tree(node* root0, vector &vec), which takes a root of a Binary tree and vector array vec containing the values of nodes.
Expected Time Complexity: O(1).
Expected Auxiliary Space: O(1).
Constraints:
vec.length = 7
1<=vec[i]<=100

Source: geeksforgeeks | Difficulty: EASY

Starter code: #User function Template for python3



class Solution:

    def createTree(self, root, l):

        # Code here

Solutions:
class Solution:

	def createTree(self, root, l):
		root.left = Node(arr[1])
		root.right = Node(arr[2])
		root.left.left = Node(arr[3])
		root.left.right = Node(arr[4])
		root.right.left = Node(arr[5])
		root.right.right = Node(arr[6])


class newnode:

	def __init__(self, data):
		self.val = data
		self.left = self.right = None

class Solution:

	def createTree(self, root, l):
		root.left = Node(arr[1])
		root.right = Node(arr[2])
		root.left.left = Node(arr[3])
		root.left.right = Node(arr[4])
		root.right.left = Node(arr[5])
		root.right.right = Node(arr[6])
		return


class Solution:

	def createTree(self, root, l):
		root.data = l[0]
		root.left = Node(l[1])
		root.right = Node(l[2])
		root.left.left = Node(l[3])
		root.left.right = Node(l[4])
		root.right.left = Node(l[5])
		root.right.right = Node(l[6])


class Node:

	def __init__(self, val):
		self.data = val
		self.left = None
		self.right = None

class Solution:

	def createTree(self, root, l):
		if not root:
			return None
		q = [root]
		i = 1
		while i < len(l):
			curr = q.pop(0)
			node = Node(l[i]) if l[i] != -1 else None
			curr.left = node
			q.append(node)
			i += 1
			if i < len(l):
				node = Node(l[i]) if l[i] != -1 else None
				curr.right = node
				q.append(node)
				i += 1
		return root


from collections import deque

class Solution:

	def createTree(self, root, l):
		que = deque()
		que.append(root)
		i = 1
		while i < len(l):
			node = que.popleft()
			node.left = Node(l[i])
			que.append(node.left)
			i += 1
			node.right = Node(l[i])
			que.append(node.right)
			i += 1


class Solution:

	def createTree(self, root, l):
		n1 = Node(l[1])
		n2 = Node(l[2])
		n3 = Node(l[3])
		n4 = Node(l[4])
		n5 = Node(l[5])
		n6 = Node(l[6])
		root.left = n1
		root.right = n2
		n1.left = n3
		n1.right = n4
		n2.left = n5
		n2.right = n6


class Tree:

	def __init__(self, data=0):
		self.data = data
		self.left = None
		self.right = None

class Solution:

	def createTree(self, root, l):

		def dfs(root, i):
			if root is None:
				return
			if 2 * i + 1 < len(l):
				root.left = Tree(l[2 * i + 1])
				dfs(root.left, 2 * i + 1)
			if 2 * i + 2 < len(l):
				root.right = Tree(l[2 * i + 2])
				dfs(root.right, 2 * i + 2)
		dfs(root, 0)
		return root


class Tree:

	def __init__(self, data=0):
		self.data = data
		self.left = None
		self.right = None

class Solution:

	def createTree(self, root, l):
		q = [[root, 0]]
		while len(q):
			(s, i) = q.pop(0)
			if 2 * i + 1 < len(l):
				s.left = Tree(l[2 * i + 1])
				q.append([s.left, 2 * i + 1])
			if 2 * i + 2 < len(l):
				s.right = Tree(l[2 * i + 2])
				q.append([s.right, 2 * i + 2])
		return root


import collections

class Solution:

	def createTree(self, root, l):
		q = collections.deque([root])
		i = 1
		while i < len(l):
			temp = q.popleft()
			temp.left = Node(l[i])
			q.append(temp.left)
			temp.right = Node(l[i + 1])
			q.append(temp.right)
			i += 2


class Solution:

	def createTree(self, root, l):
		q = []
		q.append(root0)
		i = 1
		n = len(l)
		while i < n:
			root = q.pop(0)
			left = Node(l[i])
			root.left = left
			i += 1
			q.append(left)
			right = Node(l[i])
			root.right = right
			i += 1
			q.append(right)


from collections import deque

class Solution:

	def createTree(self, root, l):
		q = deque()
		q.append(root)
		i = 1
		n = len(l)
		while i < n:
			root = q.popleft()
			left = Node(l[i])
			i += 1
			root.left = left
			q.append(left)
			if i >= n:
				break
			right = Node(l[i])
			i += 1
			root.right = right
			q.append(right)


from collections import deque
import math

class Solution:

	def createTree(self, root, l):
		q = deque()
		q.append(root)
		for i in range(0, int(math.log(len(l) + 1, 2))):
			node = q.popleft()
			node.left = Node(l[2 * i + 1])
			node.right = Node(l[2 * i + 2])
			q.append(node.left)
			q.append(node.right)


class Solution:

	def createTree(self, root, l):
		queue = [root]
		i = 1
		while queue and i < len(l):
			curr_node = queue.pop(0)
			if l[i] is not None:
				curr_node.left = Node(val=l[i])
				queue.append(curr_node.left)
			i += 1
			if i < len(l) and l[i] is not None:
				curr_node.right = Node(val=l[i])
				queue.append(curr_node.right)
			i += 1
		return root


from queue import Queue

class Solution:

	def createTree(self, root, v):
		q = Queue()
		q.put(root0)
		for i in range(1, len(v), 2):
			temp = q.get()
			temp.left = Node(v[i])
			q.put(temp.left)
			temp.right = Node(v[i + 1])
			q.put(temp.right)


from queue import Queue

class Solution:

	def createTree(self, root0, v):
		q = Queue()
		q.put(root0)
		iterator = 1
		length = len(v)
		while iterator < length:
			temp = q.get()
			leftNode = Node(v[iterator])
			temp.left = leftNode
			q.put(leftNode)
			iterator += 1
			rightNode = Node(v[iterator])
			temp.right = rightNode
			q.put(rightNode)
			iterator += 1


class Solution:

	def createTree(self, root, l):
		root1 = Node(l[1])
		root2 = Node(l[2])
		root3 = Node(l[3])
		root4 = Node(l[4])
		root5 = Node(l[5])
		root6 = Node(l[6])
		root.left = root1
		root.right = root2
		root1.left = root3
		root1.right = root4
		root2.left = root5
		root2.right = root6


class Node:

	def __init__(self, val):
		self.val = val
		self.left = None
		self.right = None

class Solution:

	def createTree(self, root, vec):
		i = 1
		queue = [root]
		while i < len(vec):
			curr = queue[0]
			queue = queue[1:]
			curr.left = Node(vec[i])
			i += 1
			queue.append(curr.left)
			if i < len(vec):
				curr.right = Node(vec[i])
				i += 1
				queue.append(curr.right)


class Solution:

	def createTree(self, root, l):
		q = []
		q.append(root)
		for i in range(1, len(l), 2):
			temp = q.pop(0)
			temp.left = Node(l[i])
			q.append(temp.left)
			temp.right = Node(l[i + 1])
			q.append(temp.right)


class Solution:

	def createTree(self, root, l):
		qu = [root]
		ind = 1
		while ind < len(l):
			temp = qu.pop(0)
			if ind < len(l):
				temp.left = Node(l[ind])
				ind += 1
				qu.append(temp.left)
			if ind < len(l):
				temp.right = Node(l[ind])
				ind += 1
				qu.append(temp.right)
		return root


class Solution:

	def createTree(self, root, l):
		for i in range(1, len(l) - 1):
			root.left = l[i - 1]
			root.right = l[i - 1]


class Solution:

	def createTree(self, root, l):
		for i in range(3):
			root.left = Node(l[2 * i + 1])
			root.right = Node(l[2 * i + 2])
		return root


class Node:

	def __init__(self, data):
		self.data == None
		self.left == None
		self.right == None

class Solution:

	def createTree(self, root, l):
		q = [root]
		i = 1
		while i < len(l):
			node = q.pop(0)
			left = Node(l[i])
			i += 1
			node.left = left
			q.append(left)
			if i >= len(l):
				break
			right = Node(l[i])
			i += 1
			node.right = right
			q.append(right)


class Solution:

	def createTree(self, root, l):
		return 1


from collections import deque

class Solution:

	def createTree(self, root, l):
		q = deque()
		q.append(root)
		i = 1
		temp = root
		while q:
			ele = q.popleft()
			left = l[i] if i < len(l) else None
			right = l[i + 1] if i < len(l) else None
			if left:
				q.append(left)
			if right:
				q.append(right)
			i += 2
		return root


class BTree:

	def __init__(self, data):
		self.data = data
		self.left = None
		self.right = None

class Solution:

	def createTree(self, root, l):
		root.left = BTree(l[1])
		root.right = BTree(l[2])
		x = root.left
		x.left = l[3]
		x.right = l[4]
		y = root.right
		y.left = l[5]
		y.right = l[6]


class Solution:

	def createTree(self, root, l):
		root = Node(l[0])


class Solution:

	def createTree(self, root, l):
		node1 = Node(l[0])
		node2 = Node(l[1])
		node3 = Node(l[2])
		node4 = Node(l[3])
		node5 = Node(l[4])
		node6 = Node(l[5])
		node7 = Node(l[6])
		node1.left = node2
		node1.right = node3
		node2.left = node4
		node2.right = node5
		node3.left = node6
		node3.right = node7


class Solution:

	def createTree(self, root, l):
		q = [root]
		i = 1
		while q and i < 7:
			s = q.pop(0)
			t = l[i]
			s.left = Node(t)
			q.append(s.left)
			i += 1
			if i >= 7:
				break
			t = l[i]
			s.right = Node(t)
			q.append(s.right)
			i += 1
		return root


class Solution:

	def __init__(self):
		self.kali = None

	def place(self, root):
		if root.left == None and root.right == None:
			self.kali = root
			return
		self.place(root.left)
		self.place(root.right)

	def createTree(self, root, l):
		i = 1
		while i < len(l):
			self.place(root)
			self.kali.left = Node(l[i])
			self.kali.right = Node(l[i + 1])
			i = i + 2
		return root