## Amazon Interview Question for SDE-2s

Country: United States
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
1
of 1 vote

``````def recur_clone(tree):
def __recur_clone(root):
if not root:
return None
node = BT._Node(root.val)
node.left = __recur_clone(root.left)
node.right = __recur_clone(root.right)
return node
ct = BT()
ct.root = __recur_clone(tree.root)
return ct``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

Node {
public string Value{get;set}
public Node Left {get;set;}
public Node Right{get;set;}
}

Node CloneNode(Node n1)
{

if(n1 != null)
{
Node c = new Node{
Value = n1.Value
};
c.Left = CloneNode(n1.Left);
c.Right = CloneNode(n1.Right);
}
}

Comment hidden because of low score. Click to expand.
0
of 0 vote

Cloning with recursion is trivial. Was it asked to be done without recursion ?

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````node  *clone( root )
{
if (root == NULL ) : return root;

//create new node and make it a copy of node pointed by root
node *temp = (node *)malloc(sizeof(node)) ;
temp->data = root-> data;    //copying data
temp->left = clone(root -> left);    //cloning left child
temp->right = clone(root -> right);  //cloning right child
return temp;
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````struct Node
{
Node* left;
Node* right;
int   val;
};

Node* clone(const Node* node)
{
Node* new_node = nullptr;

if(node)
{
new_node = new Node { nullptr, nullptr, node->val };

new_node->left  = clone(node->left);
new_node->right = clone(node->right);
}

return new_node;
}``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.