Data Structures & AlgorithmsVery hardGoldman Sachs OA · LeetCode medium-hard
How many structurally different binary search trees can be built on the keys 1..7 if the ROOT must be 3?
- A. 28
- B. 132
- C. 42
- D. 14
Correct answer: A. 28
With root 3, keys {1,2} form the left subtree in C₂ = 2 ways and keys {4,5,6,7} form the right subtree in C₄ = 14 ways, so 2 × 14 = 28. 132 is C₆ and 429 = C₇ would count all roots; 14 forgets the left side.
More Coding Interview Problems questions
- Problem: Count the ways to tile a 2 × n board with 2 × 1 dominoes and L-shaped trominoes (both rotatable). python def tilings(n): dp = [1…
- What is the time complexity of this loop? python i = n while i > 0: for j in range(i): work() # O(1) i //= 2
- Recursive quicksort can need O(n) stack depth on adversarial input. Which change GUARANTEES O(log n) extra stack space even in the worst…
- Problem: Find the shortest substring of s that contains every character of t, counting duplicates (return the leftmost one on ties)…
- Problem: Count subarrays with EXACTLY k distinct values using exactly(k) = atMost(k) − atMost(k − 1). python def atmost(a, k): cnt, l, res…
- Find the bug: the code below should return the length of the longest substring without repeating characters. python def longest(s): last…