user
Write code to convert an array of integers into a binary tree.
Input array: [1, 2, 3, 4]

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

def arrayToBinaryTree(arr):
    root = Node(arr[0])
    q = [root]
    i = 1
    while i < len(arr):
        node = q.pop(0)
        node.left = Node(arr[i])
        q.append(node.left)
        i += 1

        if i == len(arr):
            break
        
        node.right = Node(arr[i])
        q.append(node.right)
        i += 1

    return root