Research In Motion Interview Question for Software Engineer / Developers






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

first ask the interviewer how to define the order of the leaves

- Jialin November 29, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Lets say we call the order to be the dfs traversal order. Then things are quite easy.
First find all the leafs and then using DP things can be done, isnt it?

- Altruist November 29, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I meant always LEFT DFS traversal. :)

- Altruist November 29, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

map<int,int>container;
void getLeafdata(node * ptr)
{
   // Visit the left subtree
   if(ptr->left != 0)
	printLeaf(ptr->left);
   // Visit the right subtree
   if(ptr->right != 0)
	printLeaf(ptr->right);
   // If its leaf then, push the value in container, for future reference.
   if(ptr->left == 0 && ptr->right == 0)
   {
       // push it into map and increase the counter value by 1.
       container[ptr->value]++;
   }
}

void findLongest()
{
    // traverse the container map and look for the highest value.
    // finally print up the highest value.
}

- Ashutosh December 03, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

A typo in this program
"printLeaf" is actually "getLeafdata"

the correct one is:

map<int,int>container;
void getLeafdata(node * ptr)
{
   // Visit the left subtree
   if(ptr->left != 0)
	getLeafdata(ptr->left);
   // Visit the right subtree
   if(ptr->right != 0)
	getLeafdata(ptr->right);
   // If its leaf then, push the value in container, for future reference.
   if(ptr->left == 0 && ptr->right == 0)
   {
       // push it into map and increase the counter value by 1.
       container[ptr->value]++;
   }
}

void findLongest()
{
    // traverse the container map and look for the highest value.
    // finally print up the highest value.
}

- Ashutosh December 03, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

it can be visualized as 2 linked lists with a common node. trace the path of each of the nodes from the root and store it as a stack.

next use the stack as a queue with the top most being the first element.
next find the length of both the queues and then iterate on the longer one so that both point at the length now equals the shorter one.

then search for the common node

- fragzilla January 06, 2010 | Flag Reply


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