## Google Interview Question for Jr. Software Engineers

• 1
of 1 vote

Country: United States

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

Do level order traversal. At each level, check if the elements form a palindrome.

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

n must be even.

Use a subroutine , isMirrorImage( Tree a, Tree b )

``````isSymmetric ( Tree r )
{
children[]  child = r.children;

for ( s = 0; e = n -1;   )
{
isMirrorImage ( child [ s ], child [ e ] );
s ++; e --;
}

}``````

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

``````#include <iostream>
#include <vector>
using namespace std;

struct TreeNode
{
int val;
vector<TreeNode*> children;
TreeNode(int val)
{
this->val = val;
}
};

bool IsMirrorImage(TreeNode* t1, TreeNode* t2)
{
if(t1 == NULL && t2 == NULL)
{
return true;
}
if(t1 == NULL || t2 == NULL)
{
return false;
}
bool isMirrorImage = t1->val == t2->val && (t1->children).size() == (t2->children).size();
int size = (t1->children).size();
for(int i=0; isMirrorImage == true && i < size; i++)
{
isMirrorImage = IsMirrorImage((t1->children)[i], (t2->children)[size-i-1]);
}
return isMirrorImage;
}
int main() {
TreeNode* root1 = new TreeNode(1);
root1->children.push_back(new TreeNode(2));
root1->children.push_back(new TreeNode(3));
TreeNode* root2 = new TreeNode(1);
root2->children.push_back(new TreeNode(3));
root1->children.push_back(new TreeNode(2));
cout<<IsMirrorImage(root1, root2);
}``````

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.