Stealth Interview
  • Features
  • Pricing
  • Blog
  • Login
  • Sign up

Leetcode #1379: Find a Corresponding Node of a Binary Tree in a Clone of That Tree

In this guide, we solve Leetcode #1379 Find a Corresponding Node of a Binary Tree in a Clone of That Tree in Python and focus on the core idea that makes the solution efficient.

You will see the intuition, the step-by-step method, and a clean Python implementation you can use in interviews.

Leetcode

Problem Statement

Given two binary trees original and cloned and given a reference to a node target in the original tree. The cloned tree is a copy of the original tree.

Quick Facts

  • Difficulty: Easy
  • Premium: No
  • Tags: Tree, Depth-First Search, Breadth-First Search, Binary Tree

Intuition

We need to explore a structure deeply before backing up, which suits DFS.

DFS keeps local context on the call stack and is easy to implement recursively.

Approach

Define a recursive DFS that carries the necessary state.

Combine child results as the recursion unwinds.

Steps:

  • Define a recursive DFS with state.
  • Visit children and combine results.
  • Return the final aggregation.

Example

Input: tree = [7,4,3,null,null,6,19], target = 3 Output: 3 Explanation: In all examples the original and cloned trees are shown. The target node is a green node from the original tree. The answer is the yellow node from the cloned tree.

Python Solution

# Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: def getTargetCopy( self, original: TreeNode, cloned: TreeNode, target: TreeNode ) -> TreeNode: def dfs(root1: TreeNode, root2: TreeNode) -> TreeNode: if root1 is None: return None if root1 == target: return root2 return dfs(root1.left, root2.left) or dfs(root1.right, root2.right) return dfs(original, cloned)

Complexity

The time complexity is O(n)O(n)O(n), and the space complexity is O(n)O(n)O(n). The space complexity is O(n)O(n)O(n).

Edge Cases and Pitfalls

Watch for boundary values, empty inputs, and duplicate values where applicable. If the problem involves ordering or constraints, confirm the invariant is preserved at every step.

Summary

This Python solution focuses on the essential structure of the problem and keeps the implementation interview-friendly while meeting the constraints.


Ace your next coding interview

We're here to help you ace your next coding interview.

Subscribe
Stealth Interview
© 2026 Stealth Interview®Stealth Interview is a registered trademark. All rights reserved.
Product
  • Blog
  • Pricing
Company
  • Terms of Service
  • Privacy Policy