Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

For the second example, how are you supposed to merge subtrees to form a single tree?

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

I think in that case you create new tree from the left and right datas through insertion.

- ba127004 February 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

It's not clear to me what we need to do when the we are returning the middle of the tree.
If the specified height starts from 0 then:

class Node:
    left , right, data = None, None, 0    
    def __init__(self, data, l, r):
        # initializes the data members
        self.left = l
        self.right = r
        self.data = data

def copyToH(n, h, H):
  if h <= H:
    lc = copyToH(n.left,  h+1, H)
    rc = copyToH(n.right, h+1, H)
    return new Node(n.data, lc, rc)
  else: return None

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

is it the same problem where you have to find out the tree with K distance from root?

- debnathch February 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I don't understand what you ask? More details?

- stupid February 24, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

wrong question - or incomplete

- guru March 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Question not clear. I suppose you want to traverse a specific interval of a binary tree. The code is pre-order traversal.

public static void traverseByInterval(BinaryTreeNode root, int l, int h) {
    if (root == null) {
      return;
    }
    if (l > h) {
      return;
    }
    if (l <= 0 && h >= 0) {
      System.out.print(root.data + " ");
    }
    traverseByInterval(root.left, l - 1, h - 1);
    traverseByInterval(root.right, l - 1, h - 1);
  }

- Yue March 25, 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