Grokking Tree Coding Patterns for Interviews
Ask Author
Back to course home

0% completed

Solution: Create Binary Tree From Descriptions
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

You are given a 2D list called descriptions. Each element in descriptions represents a relationship in a binary tree. The element descriptions[i] = [parent<sub>i</sub>, child<sub>i</sub>, isLeft<sub>i</sub>] tells us that parent<sub>i</sub> is the paent of child<sub>i</sub>. The isLeft<sub>i</sub> value can be either 1 or 0:

  • If isLeft<sub>i</sub> is 1, childi is the left child of parent<sub>i</sub>.
  • If isLeft<sub>i</sub> is 0, child<sub>i</sub> is the right child of parent<sub>i</sub>.

Build this binary tree from the given description and return its root node

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible