← Atlassian Interview Insights

Atlassian·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
Apr 2026

Summary

Coding round for an ML Engineer role at Atlassian. One algorithmic question, a tricky LCA variant, and it was more involved than the classic version I'd practiced.

Questions Asked (1)

Q1

Given the root of a binary tree and two node values p and q, return their lowest common ancestor only if both nodes actually exist in the tree. If either is missing, return null.

Algorithms & Data Structures
Author's notes

This is LC 1644, the nastier sibling of the standard LCA problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a post-order DFS that returns a status for each subtree: whether p and q were found and the LCA if both are found. At each node, combine results from left and right subtrees; if both nodes are found in different subtrees or one is the current node, the current node is the LCA. After traversal, return the LCA only if both nodes were found; otherwise return null.

Pro tip: Explicitly discuss how your solution handles edge cases like p or q being the root, one node being an ancestor of the other, and duplicate values (if allowed). This shows thoroughness and prevents hidden bugs.

1. Clarify assumptions and edge cases

Ask if node values are unique and if p and q can be the same node. Confirm the definition of LCA and that both nodes must exist.

2. Design a recursive DFS with status reporting

Define a helper that returns whether p and q are found in the subtree and the LCA if both are found. Combine results from left and right children.

3. Determine LCA at each node

If the current node is p or q, it could be the LCA if the other is in its subtree. If left and right subtrees each contain one of p and q, the current node is the LCA.

4. Validate existence and return result

After traversal, check if both nodes were found. If not, return null; otherwise return the identified LCA.

5. Analyze complexity and test

State time and space complexity (O(n) time, O(h) space). Walk through examples including missing nodes and ancestor cases.

Key Points to Mention

  • Post-order traversal to process children before parent
  • Tracking found status for p and q separately
  • Handling the case where one node is an ancestor of the other
  • Returning null if either node is not present
  • Time complexity O(n) and space complexity O(h) due to recursion stack
  • Edge cases: empty tree, p or q not in tree, p equals q

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