← Atlassian Interview Insights

Atlassian·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Atlassian coding round, one tree problem the whole time. Felt manageable until I started second-guessing my base cases mid-interview.

Questions Asked (1)

Q1

Given a binary tree root and two target node references, find the lowest common ancestor of the two nodes. Make sure to handle edge cases like null nodes, a target that doesn't exist in the tree, a single-node tree, and the case where both targets are the same node.

Algorithms & Data Structures
Author's notes

I knew the standard recursive approach going in, propagate a found-flag or the node itself back up the tree.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and edge cases first, then propose a recursive solution that traverses the tree once, returning the LCA when found. Discuss time and space complexity, and mention how you would handle the specified edge cases explicitly.

Pro tip: Mention that you would verify the existence of both nodes before or during the traversal to avoid incorrect results when a target is missing, and consider iterative approaches for very deep trees to avoid stack overflow.

1. Clarify requirements and edge cases

Ask about tree properties (binary tree vs BST), whether parent pointers exist, and confirm handling of null nodes, missing targets, single-node tree, and identical targets.

2. Outline recursive approach

Explain a post-order traversal: if current node is null or matches either target, return current node; otherwise recurse left and right, and if both return non-null, current node is the LCA.

3. Address edge cases explicitly

Detail how the algorithm handles null root, missing targets (by tracking found flags or returning null), single-node tree (root is LCA if both targets match), and identical targets (return the node itself).

4. Analyze complexity and trade-offs

State time complexity O(n) and space complexity O(h) for recursion, and discuss iterative alternatives (e.g., using parent pointers or path lists) and their trade-offs.

5. Test with examples

Walk through a few test cases: both nodes in different subtrees, one node ancestor of the other, missing node, and same node, to validate correctness.

Key Points to Mention

  • Definition of LCA: lowest node that has both targets as descendants (a node can be a descendant of itself).
  • Recursive post-order traversal: return node if it matches a target or if both subtrees return non-null.
  • Handling missing targets: use a wrapper or boolean flags to ensure both nodes exist; otherwise return null.
  • Edge case: both targets same node -> LCA is that node.
  • Edge case: single-node tree -> if both targets are that node, return it; else null.
  • Time and space complexity: O(n) time, O(h) space for recursion; iterative alternatives for deep trees.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.