Data Structures & AlgorithmsHardTCS NQT · Accenture

Problem: A binary tree is given in preorder (root first, then left subtree, then right subtree) as 8, 3, 1, 6, 4, 7, 10, 14, 13 and inorder as 1, 3, 4, 6, 7, 8, 10, 13, 14. What is the value of the root of the left subtree of the root?

  1. A. 4
  2. B. 2
  3. C. 5
  4. D. 3

Correct answer: D. 3

The first preorder value is the root, and its position in inorder splits the left and right subtrees. The left child of the root is the first value of the left subtree's preorder block.

More Coding Interview Problems questions

Exams that ask this topic