Skip to content

Bug Report for lowest-common-ancestor-in-binary-search-tree #4417

@rara-007

Description

@rara-007

Bug Report for https://neetcode.io/problems/lowest-common-ancestor-in-binary-search-tree

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.

I think this solution is not optimal but this should also be accepted but getting below error

Traceback (most recent call last):
File "/box/script.py", line 84, in
raise TypeError(f"Your output was {outputNode}, but the expected return type is TreeNode")
TypeError: Your output was None, but the expected return type is TreeNode

if root is None or root == p or root == q:
return root

    left = self.lowestCommonAncestor(root.left, p, q)
    right = self.lowestCommonAncestor(root.right, p, q)

    if left and right:
        return root
    
    if left is not None:
        return left
    else:
        return right

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions