Amazon Interview Question for SDE1s


Country: United States




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

Given a level m and k leaves to add for the (m+1)'th level, I can do it in 2*C(m, k/2) ways.

Assuming you mean height-balanced binary trees, and assuming the 'preorder sequence length' just means the number of nodes in the tree (n), we can find a minimum height h such that

2^h - 1 <= n && 2^(h+1) - 1 > n

We then compute 2 numbers:
m = 2^h
k = (n - 2^h + 1)

That's it! We return our previous formula: 2*C(m, k/2) = 2*C(2^h, (n - 2^h + 1))

- Killedsteel March 02, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Since it is a balanced tree, the only possible combinations can be in last level
Height h=log2(n)+1
Nodes N=h^2-1
Leaves L=N/2+1
Non Leaves nl=N-L
Leaves l=n-nl
C(L,l)

- Anonymous March 06, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Do you mean number of possible trees?

- Anonymous March 18, 2017 | 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