FastPrepCorresponding Node in a Cloned Tree
Problems/Corresponding Node in a Cloned Tree

Corresponding Node in a Cloned Tree

Apple logoApple● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The corresponding-clone-node task and non-mutation requirement match the source at about 90%. The distinct-value convention and finite validity bounds make the omitted reference interface explicit.

You get two binary trees, original and cloned. The second tree is a separate copy of the first. Both have the same shape and the same value at each position. You are also given a target node in the original tree. Return the ID of its corresponding node in the cloned tree, which is the node in the same position. Do not change either tree.

Each tree is a list of rows [nodeId,value,leftId,rightId], in any order. A child ID of -1 means there is no child. The root IDs are originalRoot and clonedRoot. targetId is the ID of a node that exists in the original tree.

Node values are unique within each tree. No node ID appears in both trees. A node value may be the same number as some node ID, so make sure you return an ID, not a value.

Function

correspondingCloneNode(original: int[][], cloned: int[][], originalRoot: int, clonedRoot: int, targetId: int) → int

Examples

Example 1

original = [[10,7,20,30],[20,4,-1,-1],[30,3,-1,-1]]cloned = [[100,7,200,300],[200,4,-1,-1],[300,3,-1,-1]]originalRoot = 10clonedRoot = 100targetId = 20return = 200

The target, ID twenty, is the left child of the original root. The cloned root's left child sits in the same position. Its ID, two hundred, is the answer.

Example 2

original = [[10,7,20,30],[20,4,-1,-1],[30,3,-1,-1]]cloned = [[100,7,200,300],[200,4,-1,-1],[300,3,-1,-1]]originalRoot = 10clonedRoot = 100targetId = 10return = 100

Here the target is the original root, ID ten. Its corresponding node is the cloned root, so the answer is that root's ID, one hundred.

Constraints

  • Both inputs are valid, nonempty binary trees. Each tree has n nodes, where 1 <= n <= 20000.
  • Node IDs are distinct integers in [0,10^9]. Each child ID points to a node in the same tree, or is -1.
  • Node values are unique integers in [-10^9,10^9]. Nodes in the same position in both trees have equal values.

More Apple Onsite Interview questions

  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Topological OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • FIFO Mutex Operation TraceONSITE INTERVIEW · Seen Oct 2026
  • Implement Hit CounterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Parse Nested HTML into a TreeONSITE INTERVIEW · Seen Oct 2026
  • Thread-Safe Concurrent Linked ListONSITE INTERVIEW · Seen Sep 2026
  • Palindrome Match PercentageONSITE INTERVIEW · Seen Sep 2026
  • Binary Tree Nodes at Distance KONSITE INTERVIEW · Seen Aug 2026
  • BST to Sorted Circular Doubly Linked ListONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Diagonal Traversal of a Binary TreeAmazon · ONSITE INTERVIEW
  • Render an Org Chart and Find Skip-Level PairsSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
  • Find Leaves of a Binary TreeLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Delete Nodes and Return Forest RootsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Render a Task Tree from CSV RowsStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Filter Undesired Comments and Their DescendantsReddit · PHONE SCREEN · ONSITE INTERVIEWReddit interview questions
  • JSON Path Lookup with Implicit Array WildcardsMongoDB · ONSITE INTERVIEWMongoDB interview questions
  • Delete and Compact a Forest SubtreePinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
  • Onion-Peel Layers of a Binary TreeeBay · ONSITE INTERVIEWeBay interview questions

Interview reports that mention this question

  • Apple India SWE New Grad Interviews: 5 Experiences

Apple interview experiences

  • Apple SWE Phone Screen: Subarray Products: 1 Experience
  • Apple New Grad SWE Java, Coding and Manager Rounds: 1 Experience
  • Apple AI Coding and Related Interviews: 17 Experiences
  • Apple New Grad SWE Phone Screens: 12 Experiences (Part 3 of 3)
  • Apple New Grad SWE and Embedded: 16 Experiences (Part 2 of 3)
All Apple interview questionsSee Apple hiring insights
Saved
class Solution {
    public int correspondingCloneNode(int[][] original, int[][] cloned, int originalRoot, int clonedRoot, int targetId) {
        // Write your solution here.
    }

}
Checking account…