educative.io

Need some help with queue based complexity and recursion

def find_minimum_depth(root):
  if not root:
    return -1

  left, right = find_minimum_depth(root.left), find_minimum_depth(root.right)

  if left >= right:
    return left + 1
  else:
    return right + 1

Should we use queue for this question while we can do it with recursion? Can anybody explain the pros and cons considering the queue based solution?

Your solution is incorrect and happens to pass the given tests (I think the courses on this website don’t really have comprehensive test cases).

Your solution outputs the maximum number of edges from a leaf node to the root.