     "source": [
      "def __check_balance__(root):\n",
      "    if not root:\n",
      "        return (True, 0, 0)\n",
      "    left_balanced, left_min_h, left_max_h = __check_balance__(root.left)\n",
      "    right_balanced, right_min_h, right_max_h = __check_balance__(root.right)\n",
      "    min_h = min(left_min_h, right_min_h) + 1\n",
      "    max_h = max(left_max_h, right_max_h) + 1\n",
      "    balanced = left_balanced and right_balanced and abs(max_h - min_h) <= 1\n",
      "    return (balanced, min_h, max_h)\n",
      "\n",
      "def check_balance(root):\n",
      "    balanced, _, _ = __check_balance__(root)\n",
      "    return balanced"
 
</s> remove     "def __check_balance__(root):\n",
 </s> add     "def _check_balance(root):\n", </s> remove     "    balanced, _, _ = __check_balance__(root)\n",
 </s> add     "    if root is None:\n",
    "        return False\n",
    "    balanced, _, _ = _check_balance(root)\n",
    "    left_balanced, left_min_h, left_max_h = _check_balance(root.left)\n",
    "    right_balanced, right_min_h, right_max_h = _check_balance(root.right)\n",
    "    min_h = 1 + min(left_min_h, right_min_h)\n",
    "    max_h = 1 + max(left_max_h, right_max_h)\n",
    "    balanced = left_balanced and right_balanced and abs(max_h-min_h) <= 1\n",
     "source": [
      "def __check_balance__(root):\n",
      "    if not root:\n",
      "        return (True, 0, 0)\n",
    "    left_balanced, left_min_h, left_max_h = _check_balance(root.left)\n",
    "    right_balanced, right_min_h, right_max_h = _check_balance(root.right)\n",
    "    min_h = 1 + min(left_min_h, right_min_h)\n",
    "    max_h = 1 + max(left_max_h, right_max_h)\n",
    "    balanced = left_balanced and right_balanced and abs(max_h-min_h) <= 1\n",
    "    left_balanced, left_min_h, left_max_h = _check_balance(root.left)\n",
    "    right_balanced, right_min_h, right_max_h = _check_balance(root.right)\n",
    "    min_h = 1 + min(left_min_h, right_min_h)\n",
    "    max_h = 1 + max(left_max_h, right_max_h)\n",
    "    balanced = left_balanced and right_balanced and abs(max_h-min_h) <= 1\n",
    "    left_balanced, left_min_h, left_max_h = _check_balance(root.left)\n",
    "    right_balanced, right_min_h, right_max_h = _check_balance(root.right)\n",
    "    min_h = 1 + min(left_min_h, right_min_h)\n",
    "    max_h = 1 + max(left_max_h, right_max_h)\n",
    "    balanced = left_balanced and right_balanced and abs(max_h-min_h) <= 1\n",
    "    left_balanced, left_min_h, left_max_h = _check_balance(root.left)\n",
    "    right_balanced, right_min_h, right_max_h = _check_balance(root.right)\n",
    "    min_h = 1 + min(left_min_h, right_min_h)\n",
    "    max_h = 1 + max(left_max_h, right_max_h)\n",
    "    balanced = left_balanced and right_balanced and abs(max_h-min_h) <= 1\n",
    "    left_balanced, left_min_h, left_max_h = _check_balance(root.left)\n",
    "    right_balanced, right_min_h, right_max_h = _check_balance(root.right)\n",
    "    min_h = 1 + min(left_min_h, right_min_h)\n",
    "    max_h = 1 + max(left_max_h, right_max_h)\n",
    "    balanced = left_balanced and right_balanced and abs(max_h-min_h) <= 1\n",
      "    return (balanced, min_h, max_h)\n",
      "\n",
      "def check_balance(root):\n",
      "    balanced, _, _ = __check_balance__(root)\n",
      "    return balanced"
keep keep keep keep replace replace replace replace replace keep keep keep keep keep
 Polish check tree balance challenge and solution (#80)

Update constraints, test cases, tests, and code. 
graphs_trees/check_balance/check_balance_solution.ipynb