     },
     "outputs": [],
     "source": [
      "def check_balance(root):\n",
      "    if check_height(root) == -1:\n",
      "        return False\n",
      "    else:\n",
      "        return True\n",
      "\n",
      "def check_height(root):\n",
      "    if root is None:\n",
      "        return 0\n",
      "    left_height = check_height(root.left)\n",
      "    if left_height == -1:\n",
      "        return -1\n",
      "    right_height = check_height(root.right)\n",
      "    if right_height == -1:\n",
      "        return -1\n",
      "    diff_height = left_height - right_height\n",
      "    if abs(diff_height) > 1:\n",
      "        return -1\n",
      "    else:\n",
      "        return 1 + max(left_height, right_height)"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
 
</s> remove     "* Check the height of `root.left`, if -1, return -1\n",
    "* Check the height of `root.right`, if -1, return -1\n",
    "* If the height differences is greater than 1, return -1\n",
    "* Otherwise, return 1 + max(left height, right height)\n",
 </s> add     "* Recursively check whether the left sub tree is balanced, and get its maximum and minimum height\n",
    "* Recursively Check whether the right sub tree is balanced, and get its maximum and minimum height\n",
    "* Calculate the maximum height and minimum height of the current tree\n",
    "* If both sub-trees are balanced, and the maximum and minimum height of the current tree doesn't differ by more than 1, then the current tree is balanced. Otherwise, it is not\n",
    "* Return whether the current tree is balanced, and the maximum height and minimum height of the current tree\n",
    "    balanced, _, _ = __check_balance__(root)\n",
    "    return balanced"
     },
     "outputs": [],
     "source": [
      "def check_balance(root):\n",
    "    balanced, _, _ = __check_balance__(root)\n",
    "    return balanced"
    "    balanced, _, _ = __check_balance__(root)\n",
    "    return balanced"
    "    balanced, _, _ = __check_balance__(root)\n",
    "    return balanced"
    "    balanced, _, _ = __check_balance__(root)\n",
    "    return balanced"
    "    balanced, _, _ = __check_balance__(root)\n",
    "    return balanced"
    "    balanced, _, _ = __check_balance__(root)\n",
    "    return balanced"
    "    balanced, _, _ = __check_balance__(root)\n",
    "    return balanced"
    "    balanced, _, _ = __check_balance__(root)\n",
    "    return balanced"
    "    balanced, _, _ = __check_balance__(root)\n",
    "    return balanced"
    "    balanced, _, _ = __check_balance__(root)\n",
    "    return balanced"
    "    balanced, _, _ = __check_balance__(root)\n",
    "    return balanced"
    "    balanced, _, _ = __check_balance__(root)\n",
    "    return balanced"
    "    balanced, _, _ = __check_balance__(root)\n",
    "    return balanced"
    "    balanced, _, _ = __check_balance__(root)\n",
    "    return balanced"
    "    balanced, _, _ = __check_balance__(root)\n",
    "    return balanced"
    "    balanced, _, _ = __check_balance__(root)\n",
    "    return balanced"
    "    balanced, _, _ = __check_balance__(root)\n",
    "    return balanced"
    "    balanced, _, _ = __check_balance__(root)\n",
    "    return balanced"
    "    balanced, _, _ = __check_balance__(root)\n",
    "    return balanced"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 Fix check_balance solution for a new test case 
graphs_trees/check_balance/check_balance_solution.ipynb