Amazon Interview Question for Software Engineer / Developers


Country: India
Interview Type: Written Test




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

Let a = x2 - x1 and b = y2 - y1

The answer is then C(a+b, b) (or C(a+b, a) -- these are equal) where C is the binomial coefficient function (sometimes read as "a+b choose a"). The reason is that you need to take a+b steps to reach your goal, and any b of those can be upward steps (or alternatively, any a of those can be to the right). The answer is therefore the number of different ways to pick b items from a sequence of length a+b.

Using a formula for the binomial coefficient, C(a+b, a) = (a+b)! / (a! * b!)

- eugene.yarovoi October 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

yes u r right
a=y2-y1
b=x2-x1
no. of path is c(a+b,a)=c(a+b,b)

- dhamu.31954 October 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thanks for this insightful solution.

- Richard October 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
3
of 3 vote

int countPaths(int x1, int y1, int x2, int y2) {
int count=0;
if ((x1>x2) || (y1>y2)) {
return 0;
}
if ( x1==x2 && y1==y2 ) {
return 1;
}
count = countPaths(x1+1,y1,x2,y2) + countPaths(x1,y1+1,x2,y2);
return count;
}

- sjain October 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You need some kind of memoization here to prevent the complexity from being super high.

- eugene.yarovoi October 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

didnt get you completely, its just simple recursive code.

- sjain October 29, 2012 | Flag


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