Back
Close

Reproduce binary tree

tsv
1,267 views

Task

Binary tree is traversed twise:

  1. left -> root -> right (inorder)
  2. root -> left -> right (preorder)

Having two arrays you need to reconstruct this binary tree

Solution

Implemented in python
class Node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def make_tree(inorder, preorder):
if inorder is None:
raise TypeError("inorder is None")
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Tests

Implemented in python
from impl import make_tree
def send_msg(channel, msg):
print("TECHIO> message --channel \"{}\" \"{}\"".format(channel, msg))
def success():
print("TECHIO> success true")
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants