Grokking the Coding Interview: Patterns for Coding Questions
0% completed
Problem Challenge 3: Count of Structurally Unique Binary Search Trees (hard)
.....
.....
.....
Like the course? Get enrolled and start learning!
A
Anonymous
· 2 years ago
class Solution: def countTrees(self, n): def solve(start, end): if start > end: return 1 count = 0 for i in range(start, end + 1): lefts = solve(start, i - 1) rights = solve(i + 1, end) count += lefts * rights return count return solve(1, n)
A
Anonymous
· 3 years ago
Could you please explain further why it is O(N^2) time complexity when we use memoization? Thank you!
Show 1 reply
A
Anonymous
· 4 years ago
time limit exceeded on leetcode
A
Anonymous
· 4 years ago
Why is the space complexity for non memoized version 2^N? It appears to me that the space required is used by the recursion call stack which is at most the depth of n - 1?
Show 1 reply
Reading Progress
0%