Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: The binary tree with root 10, left child 5, right child 15, and 5 having right child 7, 15 having left child 12, is traversed in post-order (left, right, root). What is the third node visited?
- A. 10
- B. 7
- C. 12
- D. 15
Correct answer: C. 12
Post-order is 7, 5, 12, 15, 10, so the third node is 12. In-order (5, 7, 10, 12, 15) gives 10, pre-order (10, 5, 7, 15, 12) gives 7, and level order gives 15.
More Coding Interview Problems questions
- Problem: A list starts as [8, 3, 5]. Three insertion steps add the numbers 4, 9, 1 at the front of the list (each is inserted at index 0)…
- Problem: A deque starts as [2, 4, 6]. The operations are: push front 1, push back 8, pop front, push back 3. What is the sum of the final…
- Problem: The string "tenet" is considered. How many of its substrings (by index range, length at least 2) are palindromes?
- Problem: Water fills a 1-dimensional container with walls of heights [4, 1, 3, 1, 2]. Each cell holds water up to the minimum of the…
- Problem: Compute the sum of all integers from 1 to 999 whose digits are all odd.
- Problem: What is the number of ways to climb 8 steps when each move is 1, 2 or 4 steps, counted as ordered sequences?