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?
- A. 4
- B. 2
- C. 5
- 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
- Problem: For the binary tree with root value 2 and children: 2 has left child 3 and right child 9; 3 has left child 1 and right child 5; 9…
- Problem: The string "banana" has its longest repeated substring (a substring occurring at least twice, overlaps allowed) of length L. What…
- Problem: How many subsequences equal to the string "abc" are contained in "aabbcbcac" (a subsequence picks positions in increasing order…
- Problem: The string "aabcccccaaa" is run-length encoded (each run becomes its letter followed by its run length, e.g. "a2b1..."). What is…
- Problem: Find the length of the shortest substring of "xaybzcxyabc" that contains all the letters a, b and c at least once.
- Problem: A Conway's Game of Life grid on a 4×4 board with alive cells at (1,0), (1,1), (1,2), (0,2) is advanced by one generation…