Data Structures & AlgorithmsModerateTCS NQT Digital · Product Company SDE

Problem: A DP solution for 'minimum coins for amount A using c denominations' with A ≤ 10⁴ and c ≤ 100 is accepted. A friend proposes plain recursion min over coins without memoisation. What is the friend's worst-case complexity?

  1. A. Exponential – roughly O(c^(A / smallest coin)) because subproblems are recomputed
  2. B. O(A · c), the same as the DP
  3. C. O(A log c)
  4. D. O(c²)

Correct answer: A. Exponential – roughly O(c^(A / smallest coin)) because subproblems are recomputed

Without memoisation the recursion tree branches c ways at each level and is up to A levels deep, recomputing the same amounts many times. Memoising on the amount collapses it to A·c states and transitions, about 10⁶ here.

More Coding Interview Problems questions

Exams that ask this topic