Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE
Problem: A function has T(n) = T(n − 1) + T(n − 2) + O(1) without memoisation. What is its growth?
- A. Θ(n²)
- B. Θ(φⁿ) ≈ Θ(1.618ⁿ) – exponential
- C. Θ(2ⁿ) exactly
- D. Θ(n log n)
Correct answer: B. Θ(φⁿ) ≈ Θ(1.618ⁿ) – exponential
The call tree has fib(n)-many leaves, which grows like φⁿ. It is O(2ⁿ) as an upper bound, but the tight bound is φⁿ. Memoisation turns it into Θ(n).
More Coding Interview Problems questions
- Problem: Dijkstra is run with a binary heap but WITHOUT the 'skip stale entry' check (if d > dist[u]: continue). What happens?
- Problem: n ≤ 10⁵ points on a line; answer 'how many points lie in [l, r]?' for 10⁵ queries. What is the simplest efficient solution?
- Problem: Implement a queue using two stacks and report the dequeued values. python class Q: def init(self): self.inb, self.out = [], []…
- Problem: Evaluate a basic calculator expression with +, −, parentheses and spaces. python def calc(s): res, num, sign, st = 0, 0, 1, []…
- Problem: Decode a string like 3[a2[c]] where k[...] repeats the bracket content k times. python def decode(s): st, cur, k = [], '', 0 for…
- Problem: For each element, find the next greater element in a circular array (−1 if none). python def ngecircular(a): n = len(a); res =…