Apple Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

public boolean isMirror(Node root1,Node root2)
{
	if(root1==null && root2==null) return true;
        if((root1==null && root2!=null)||(root2==null && root1!=null)  return false;
        if(root1.get() != root2.get())  return false;
        return isMirror(root1.left , root2.right) && isMirror(root1.right , root2.left);
}

- Prakash October 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

second line should be below:
if(root1==null||root2==null) return false;

- freemail165 April 13, 2014 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

Inorder traversal of T1 will be reverse of inorder traversal of T2, if they are mirror image of each other.

- Do the inorder traversal of T1 and store the result in a stack. 
- Do the inorder traversal of T2 and compare the results with the popped elements from the  
  stack

- Chander Shivdasani October 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

int identical(struct node* a, struct node* b)
{
if (a==NULL && b==NULL){return(true);}
else if (a!=NULL && b!=NULL)
{
return(a->data == b->data &&
identical(a->left, b->right) &&
identical(a->right, b->left));
}
else return(false);
}

- Anonymous October 16, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

wat tree type is it friend?

- rohit's mom October 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
3
of 3 votes

Binary tree

- techpanja October 02, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Question never said it was a binary tree. By definition tree is a connected graph with no cycles with one vertex named a root.
I don't like recursive solutions for this one as in this case for very deep trees we might ran out of stack quite fast. While in breadth search solution our memory complexity is bounded by "widest" part of the tree.

- M42 September 05, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

careercup.com/question?id=5096976739729408#stq=mirror%20binary%20tree&stp=1

- / October 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

step 1: do In order traversal for first tree and store the result in one array.
step 2: start in order traversal for the second tree and compare the node value with result array, if both match continue the traversal and both tree are completed in traversal, they are mirror image trees or else stopped...and the result is not matched..

- Senthilkumar October 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

In-order traversal for both of the tree (mirror/non-mirror) should in form of palindrome.
For Ex:

BDACFE and EFCADB

- PKT October 03, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Suppose we have trees p and q.
2. Swap the left and right nodes of q.
3. Check is p and q are structurally equivalent
4. Swap the left and right nodes of q to get the original tree back.

- akshaycj47 November 08, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Correction:
1. Suppose we have trees p and q.
2. Find the mirror of q.
3. Check is p and q are structurally equivalent
4. Find the mirror of q to get the original tree back.

- akshaycj47 November 08, 2015 | Flag


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More