Amazon Interview Question for Interns


Country: United States
Interview Type: Phone Interview




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

Here is the foundational one :
math.stackexchange.com/questions/1422686/number-of-paths-in-a-mxn-matrix
Here is the code you need in normal language :
geeksforgeeks.org/print-all-possible-paths-from-top-left-to-bottom-right-of-a-mxn-matrix/

- NoOne October 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

// ZoomBA
def careercup(path, x, y, M, N){
  if ( x > M || y > N ) return 0
  if ( x == M  && y == N ) {
    println( path )
    return 1 
  }
  result = ( careercup( path + str('(%s,%s)', x+1,y) , x + 1, y , M, N) + 
             careercup( path + str('(%s,%s)', x,y+1) , x, y + 1 , M, N) +
             careercup( path + str('(%s,%s)', x+1,y+1) , x + 1, y + 1, M, N) )
}
println ( careercup('(0,0)', 0, 0, 2, 2) )

- NoOne October 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private static int findPaths(int i, int j){
int paths = 0;
calc++;
if (i == (m-1) && j == (n-1)) {
return 1;
}
calc++;
if(i+1 < m) {
paths += findPaths(i+1,j);
}
calc++;
if(j+1 < n) {
paths += findPaths(i,j+1);
}
calc++;
if(i+1 < m && j+1 < n) {
paths += findPaths(i+1,j+1);
}
return paths;
}

private static int findPathsOpt(int i, int j){
if (store[i][j] != 0) {
return store[i][j];
} else {
int paths = 0;

if (i == (m-1) && j == (n-1)) {
return 1;
}

if(i+1 < m) {
paths += findPathsOpt(i+1,j);
}

if(j+1 < n) {
paths += findPathsOpt(i,j+1);
}

if(i+1 < m && j+1 < n) {
paths += findPathsOpt(i+1,j+1);
}
store[i][j] = paths;
return paths;
}
}

- Swap October 13, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int paths(int m, int n){
return m == 1 || n == 1 ? 1 : paths(m-1,n) + paths(m,n-1) + paths(m-1, n-1);
}

- JJBL October 19, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream> 
#include <queue> 
using namespace std;

int careerSolution(int m, int n)
{
	int steps[m][n];
	bool visited[m][n];
	for(int i = 0; i < m; i++){
		for(int j = 0; j < n; j++){
			steps[i][j] = 0;
			visited[i][j] = false;
		}
	}
	steps[0][0] = 1;
	visited[0][0] = true;
	class coord {
	public:
		coord(int lhs, int rhs)
		{
			x = lhs;
			y = rhs;
		}
		coord operator=(coord& rhs){
			this->x = rhs.x;
			this->y = rhs.y;
		}
		int x;
		int y;
	};
	coord start(0, 0);
	queue<coord> q;
	q.push(start);

	int dx[3] = { 1, 0, 1 };
	int dy[3] = { 0, 1, 1 };
	while(!q.empty()){
		coord current = q.front();
		q.pop();
		for(int i = 0; i < 3; i++){
			coord next(current.x + dx[i], current.y + dy[i]);
			if(next.x < m && next.y < n){
				steps[next.x][next.y] += steps[current.x][current.y];
				if(!visited[next.x][next.y]){
					q.push(next);
					visited[next.x][next.y] = true;
				}
			}
		}
	}
	return steps[m-1][n-1];
}

- f0vea December 02, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class RobotMove{
    int matrix[][];
    int counter;
    int size;
    int width;
    int height;
    
    RobotMove(int n, int m){
        matrix = new int[n][m];
        counter = 0;
        width = n;
        height = m;
        move(0,0,"0,0");
    }
    
    public void move(int n, int m, String path){
        if (m == height-1 && n == width-1) {
            System.out.println(path);
            counter++;
        }
        if (n+1 <= width-1) move(n+1,m,path+"->"+(n+1)+","+m);
        if (m+1 <= height-1) move(n,m+1,path+"->"+(n)+","+(m+1));
    }
}

- Anonymous December 09, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class RobotMove{
    int matrix[][];
    int counter;
    int size;
    int width;
    int height;
    
    RobotMove(int n, int m){
        matrix = new int[n][m];
        counter = 0;
        width = n;
        height = m;
        move(0,0,"0,0");
    }
    
    public void move(int n, int m, String path){
        if (m == height-1 && n == width-1) {
            System.out.println(path);
            counter++;
        }
        if (n+1 <= width-1) move(n+1,m,path+"->"+(n+1)+","+m);
        if (m+1 <= height-1) move(n,m+1,path+"->"+(n)+","+(m+1));
    }
}

- edanir December 09, 2016 | 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