Amazon Interview Question for SDE-2s


Country: India
Interview Type: Written Test




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

Check this
techieme.in/techieme/dynamic-programming-distinct-paths-between-two-points/

- Sai August 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Catalan number

- amit September 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

No.
If you only allow down and right AND the matrix is square (n+1 by n+1), then the number of paths is (2n) choose (n).

The number of paths that cross the diagonal from (0,0) to (n+1, n+1) is (2n) choose (n+1)

So Catalan number of order n counts the number of paths from (0,0) to (n+1, n+1) that do not cross the diagonal:

C_n = (2n)choose(n) - (2n)choose(n+1)

The posted problem is different.

- bigphatkdawg September 19, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

What are the allowed movements?
down and right?
Along the lines?

- Isai August 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If only down and right are allowed the solution is simple by using combinatorics, in a [m][n] matrix the answer is C(m+n, m).

You can also use backtracking to find the paths, just keep adding one until all paths are exhausted.

- Alistair August 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Off by one errors :)

- bigphatkdawg September 19, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

If we assume the robot can only move down and to its right.

/* compute the number of move of a robot
 * from (0,0) to (x,y)
 */
unsigned long long robot_table[1024][1024];
unsigned long long robot_move (int x, int y)
{
    if (x == 0) {
        return (1);
    }
    if (y == 0) {
        return (1);
    }
    if (robot_table[x][y]) {
        return (robot_table[x][y]);
    }
    robot_table[x][y] = robot_move(x-1, y) + robot_move(x, y-1);
    return (robot_table[x][y]);
}

- ggmufc August 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

In this case the answer is:
(m+n-2)!/ { (m-1)!(n-1)! }

Because every path is associated with a permutation of the letters: RRRR(n-1 times)RRRDDDDD(m-1 times)DDDD

- bigphatkdawg September 19, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

You can use bottom up DP to solve that:
(m+n-1) choose (m-1) is equivalent to that.

- bigphatk September 19, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

(m+n-2) choose (m-1)

- bigphatkdawg September 19, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int ii = 4;
int jj = 4;

int max_path(int i, int j){

int count=0;
if(i==(ii-1) && j == (jj-1)){
return 1;
}
if(i < ii){
count += max_path(i+1,j);
}
if(j < jj){
count += max_path(i,j+1);
}
return count;

}

int _tmain(int argc, _TCHAR* argv[])
{
printf("Number of Paths: %d", max_paths(0,0));
return 0;
}

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

Ill-posed problem. Is backtracking allowed or not?

- HOLLANDAISE.DH September 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

if you can move down and right then you hv 2 possiblity only.check the below code

int no_of_path(int n1,int n2,int i,int j)
{
	if(i==n1 || j==n2)
		return 1;
	if(i==n1-1 && j==n2-1)
		return 2;
    return (no_of_path(n1,n2,i+1,j)+no_of_path(n1,n2,i,j+1));
}

- go4gold September 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.


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