Data Structures & AlgorithmsVery hardProduct Company SDE · Amazon OA
Problem: A binary tree in level order (None for absent nodes) is [5, 4, 8, 11, None, 13, 4, 7, 2, None, None, 5, 1]. How many root-to-leaf paths have values summing to exactly 22?
- A. 1
- B. 2
- C. 0
- D. 3
Correct answer: A. 1
Depth-first search carrying the running sum; a path counts only when it ends at a leaf with the target sum. Counting every node whose prefix sum equals the target counts non-leaf endpoints too.
More Coding Interview Problems questions
- Problem: Count the odd-length palindromic substrings of "racecarxyz" that are centred at index 3 (the 'e' of "racecar"), where the centre…
- Problem: What is the lexicographically next permutation of the string "bcdea" (the next arrangement in dictionary order using the letters…
- Problem: How many substrings of "abcabc" contain all three letters a, b and c at least once?
- Problem: In how many ways can a 1 × 7 strip be tiled completely with tiles of length 1, 2 and 3 (ordered arrangements of tiles count…
- Problem: A rope of integer length 10 is cut into integer pieces (at least two pieces), and the product of the piece lengths is maximised…
- Problem: How many binary strings of length 6 contain neither the substring "00" nor "11"?