Amazon Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

it is simple. let the vertical no of root is 0. the vertical no of the one left to it is -1. and another one left to this is -2. similarly on the right side.

we can have a hash map in which we can insert the vertical nos. that is when we visit root we insert 0. when we visit one left we insert -1 if the hash does not contain -1 already. while inserting increase a counter.

finally counter is the no of verticals and hash is the vertical nos. from that we can say how many on the left or on the right

- Anonymous October 22, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Here is a different solution,

puddleofriddles.blogspot.com/2012/01/count-total-number-of-vertical-columns.html

- Anonymous January 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

can u provide some more examples.

- anony October 15, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

please clarify what do u mean by verticals? Is it all the paths from root to any leaf?

- learner October 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sorry about the ambiguity. basically, from a given node, if you are traversing to left, your vertical position is shifted by -1 and if you are traversing right, your vertical position is shifted by +1.

i hope this clears the confusion.

- Avinash October 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Still not clear about what's the asking?

- man October 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

pls explain the question clearly...

- mgr October 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think it asks for (rightest's vertical - leftest's vertical + 1).

- Anonymous October 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In order traversal. Have a counter. If node left is not null decrement counter. If node right is not null increment counter. Is this what the question meant?

- persevere October 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

typedef struct BNode
{
BTree *left;
BTree *right;
} BNode;
typedef BNode *BTree;

void doNumVert(BTree bt, int vert, int &leftest, int &rightest);
int numVert(BTree bt)
{
int leftest = 0;
int rightest = 0;

if (bt == NULL)
{
return 0;
}

doNumVert(bt, 0, leftest, rightest);

return rightest - leftest + 1;
}

void doNumVert(BTree bt, int vert, int &leftest, int &rightest)
{
if (bt->left)
{
doNumVert(bt->left, vert-1, leftest, rightest);
}
else
{
if (vert < leftest)
{
leftest = vert;
}
}

if (bt->right)
{
doNumVert(bt->right, vert+1, leftest, rightest);
}
else
{
if (vert > rightest)
{
rightest = vert;
}
}
}

- Anonymous October 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Redefine BTree:
typedef struct BNode
{
BNode *left;
BNode *right;
} BNode, *BTree;

- Anonymous October 18, 2011 | 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