## InMobi Interview Question for Software Engineer / Developers

Team: InMobi
Country: India
Interview Type: In-Person

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

Morris algorithm -

1. Initialize current as root
2. While current is not NULL
If current does not have left child
a) Print currentâ€™s data
b) Go to the right, i.e., current = current->right
Else
a) Make current as right child of the rightmost node in current's left subtree
b) Go to this left child, i.e., current = current->left

``````void MorrisTraversal(struct tNode *root)
{
struct tNode *current,*pre;

if(root == NULL)
return;
current = root;
while(current != NULL)
{
if(current->left == NULL)
{
printf(" %d ", current->data);
current = current->right;
}
else
{
pre = current->left;
while(pre->right != NULL && pre->right != current)
pre = pre->right;
if(pre->right == NULL)
{
pre->right = current;
current = current->left;
}

else
{
pre->right = NULL;
printf(" %d ",current->data);
current = current->right;
}
}
}
}``````

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

``````public void TraverseInOrder(treenode root)
{
Stack<treenode> stack = new Stack<treenode>();
treenode cur = root;

while(true)
{
if(cur != null)
{
stack.push(cur);
cur = cur.left;
}
else
{
if(stack.empty())
return;

cur = stack.pop();
//do your job here, print, eat or whatever
cur = cur.right();
}
}
}``````

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

awesome

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

``````void  InOrderTraversal(BinaryTree *root)
{
stack<BinaryTree*> s;
s.push(root);
while (!s.empty())
{
BinaryTree *top = s.top();
if (top != NULL)
{
if (!top->visited)
{
s.push(top->left);
} else {
cout << top->data << " ";
s.pop();
s.push(top->right);
}
}
else
{
s.pop();
if (!s.empty())
s.top()->visited = true;
}
}
}``````

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.