Amazon Interview Question for Software Engineer in Tests






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

sorry it is binary tree

- manish August 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

For a straight binary tree do any traversal of the tree, printing each node value if it's in range.

- Anonymous August 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

yeah one can easily do and preorder traversal adn get all the nodes printed;
preorder(root)
{
if(leftchild!=null)
{
preorder(leftchild);
}
if(leftchild!=null)
{
preorder(rightchild);
}
}

- saumils1987 August 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

preorder(root)
{
print(root.element);
if(leftchild!=null)
{
preorder(leftchild);
}
if(leftchild!=null)
{
preorder(rightchild);
}
}

- saumils1987 August 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

of course you can print the node whose value is between the max and min when you execute a inorder traverse, however, using recusive may be a better solution

- leehom liang August 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void Print( node* T , int max , int min )
{
     if( T==NULL )
      return;
      
     if( T->info > max )
      {
         Print( T->left , max , min );
         
         return;
         
         }
         
      else if ( T->info < min ) 
       {
          Print( T->right , max , min );
          
          return;
          
          }
          
       else
        {
        print( T->info );
        
         Print( T->left , max , min );
          Print( T->right , max , min );
        
        
        return;
        
        }
        
        
        }

- JD September 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Run the binary search on the given tree. If the current node is greater than both the values take the left branch. In case root is less than both value take the right branch. Once its in between, only then run the inorder traversal from that root.

- ekapil2 November 15, 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