Does recursive solution count as constant extra space?

  • 3

    I have an recursive solution that got accepted. But just wondering since for the recursive function, internally the calling stack is consuming O(N) memory space where N is the depth of the recursion (in my case, it's the height of the tree), so it seems not qualified as const extra space?

  • 0

    You can discuss this with the interviewer. Strictly speaking, it does use extra memory and I personally don't consider it a constant-memory solution.

  • 0

    Strictly speaking, no, any size changing with respect to n is not constant space

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.