← Amazon questions

Clone binary tree from different machine

Filed under Amazon

Free read 3 of 3

Determine the serialization format used to transmit the tree data from the remote machine.

The question

Reconstruct or clone a binary tree whose nodes are serialized and sent from a different machine, handling pointer reconstruction across serialized boundaries.

Constraints

  • The tree may be unbalanced or skewed.
  • Serialization format must handle missing children (e.g., null markers).

Examples

Input
Serialized array: [1, 2, 3, null, null, 4, 5]
Output
Root node of the reconstructed binary tree
Why
Standard level-order or pre-order serialization with null markers allows exact tree reconstruction.

Approach

  1. Determine the serialization format used to transmit the tree data from the remote machine.

Tips

  • What they are testing: Test with an empty tree, single node, and highly unbalanced trees.
  • Common mistake: Failing to correctly account for null children during deserialization, leading to misaligned pointer mapping.

Related Amazon questions

Collected from public candidate posts and coding forums. Updated Nov 2026.