Skip to main content
LeetCode 2196, Medium. Topics: Array, Hash Table, Tree, Binary Tree. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 16 parametrized pytest cases, and a playground notebook:

Problem

You are given a 2D integer array descriptions where descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>] indicates that parent<sub>i</sub> is the parent of child<sub>i</sub> in a binary tree of unique values. Furthermore,
  • If isLeft<sub>i</sub> == 1, then child<sub>i</sub> is the left child of parent<sub>i</sub>.
  • If isLeft<sub>i</sub> == 0, then child<sub>i</sub> is the right child of parent<sub>i</sub>.
Construct the binary tree described by descriptions and return its root. The test cases will be generated such that the binary tree is valid.

Examples

Example 1
Example 2

Constraints

  • 1 <= descriptions.length <= 10^4
  • descriptions[i].length == 3
  • 1 <= parent<sub>i</sub>, child<sub>i</sub> <= 10^5
  • 0 <= isLeft<sub>i</sub> <= 1
  • The binary tree described by descriptions is valid.

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026