Grokking Data Structures & Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
Pavel Kostenko
Issue with inputs

Pavel Kostenko

Dec 26, 2024

For somewone who is new to Binary Trees your inputs doesn't make any sense.

Inputs should be searialized trees in preOrder.

So we can deserialize them in preOrder as well.

You should Either provide more information on how to use your inputs, or do not provide them at all as I believe they are not usefull, if they can not be used as inputs to a solution.

You also may provide a method which builds a tree from your inputs if you believe your inputs are correct and make sense.

First Input:

[1, 2, 3, 4, 5] // when constructed the tree manually let root = new TreeNode(1); root.left = new TreeNode(2); root.right = new TreeNode(3); root.left.left = new TreeNode(4); root.left.right = new TreeNode(5); console.log('Given tree:'); root.printPre(); root.printIn(); root.printPost(); // Outputs: // printPre (Pre Order traversal) // 1,2,4,null,null,5,null,null,3,null,null // printIn (In Order traversal) // null,4,null,2,null,5,null,1,null,3,null // printPost (Post Order traversal) // null,null,4,null,null,5,2,null,null,3,1

Expected FIRST INPUT:

[1,2,4,null,null,5,null,null,3,null,null]

By Applying the same principle

second input

[1, null, 2, null, 3]

EXPECTED SECOND INPUT

[1,null,2,null,3,null,null]

Third input

[1, 2, 3, 4, 7, null, null, null, null, null, 9]

expected third input

[1,2,4,null,null,7,null,9,null,null,3,null,null]

0

0

Comments
Comments

On this page