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;
      }
     }
   }
}

- nihaldps February 22, 2012 | Flag Reply
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();
        }
    }
}

- Ric February 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

awesome

- Piyush Beli March 22, 2012 | Flag
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;
    }
  }
}

- nueman fernandez May 17, 2013 | 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