Data Structures & AlgorithmsVery hardAccenture · Infosys OA
Problem: Which best describes the relationship between the number of valid Binary Search Trees on n distinct keys and the Catalan numbers?
- A. The count of structurally unique BSTs on n keys is exactly the nth Catalan number, C(n) = (2n choose n)/(n+1)
- B. The count equals n! (same as permutations)
- C. The count is always a power of 2
- D. The count grows linearly with n
Correct answer: A. The count of structurally unique BSTs on n keys is exactly the nth Catalan number, C(n) = (2n choose n)/(n+1)
Choosing each possible root and recursively counting left/right subtree shapes gives the Catalan recurrence C(n) = sum C(i)*C(n-1-i), whose closed form is the nth Catalan number -- the same count that governs balanced-parenthesis sequences.
More Coding Interview Problems questions
- Problem: What is the time complexity of the standard iterative binary search, and what precondition must hold for it to work correctly?
- Problem: Which best describes why DFS-based topological sort (using finish times, pushing to a stack) correctly produces a topological…
- Problem: A problem requires finding all pairs in an array that sum to a target, allowing duplicate pairs to be counted once. Which is the…
- Problem: Which statement about the time complexity of building a suffix array naively (sorting all n suffixes with standard string…
- Problem: A delivery app logs the parcel weights of a day in an array. Return the indices of the two parcels whose weights add up exactly…
- Problem: Given an unsorted array of n ≤ 10⁵ integers and a target, report whether two different positions hold values summing to the…