Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: The right-side view of a binary tree lists the rightmost node at each depth from top to bottom. For the tree with root 1, children 2 and 3, node 2 has right child 5, node 3 has right child 4, and node 5 has left child 6, what is the sum of the values in the right-side view?
- A. 8
- B. 21
- C. 15
- D. 14
Correct answer: D. 14
A level-order BFS takes the last node of each level: 1, 3, 4 (not 5, which sits left of 4) and 6, summing to 14. Following only right-child pointers stops at 1, 3, 4 (8), summing all nodes gives 21, and taking 5 at depth 2 gives 15.
More Coding Interview Problems questions
- Problem: A binary tree is given by level order [1, 2, 3, 4, 5, None, 6]. Its diameter is the largest number of edges on any path between…
- Problem: How many palindromic substrings of even length does "abbaccdd" contain?
- Problem: The string "aaaa" can be written as a concatenation of the pieces "a" and "aa" in several ways (order matters). How many such…
- Problem: The minimum ASCII delete sum to make the strings "sea" and "eat" equal is the least total ASCII value of deleted characters. Give…
- Problem: A pattern-matching task uses the string "abxcabcyabd" and the target "abc". How many length-3 windows of the text differ from…
- Problem: Using shell-style wildcards ( matches any run of characters including empty, ? matches exactly one character), how many words in…