Amazon Interview Question for Quality Assurance Engineers


Team: Ring
Country: India




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

import java.util.*;
public class PathInMatrix {
public static boolean utilityPath(int x,int y,int m,int n,int[][] mat,List<List<Integer>> path)
{
if(x==m-1 && y==n-1)
{
path.add(Arrays.asList(x,y));
path.forEach((p)->System.out.println(p.get(0)+","+p.get(1)));
return true;
}
if(x>=0 && x<m && y>=0 && y<n && mat[x][y]==1)
{
path.add(Arrays.asList(x,y));
if(utilityPath(x+1,y,m,n,mat,path) || utilityPath(x,y+1,m,n,mat,path))
return true;
path.remove(path.size()-1);
}
return false;
}
public static void getPath(int[][] mat)
{
boolean path=utilityPath(0,0,mat.length,mat[0].length,mat,new ArrayList<>());
}
public static void main(String[] args) {
int[][] mat={{1,0,0,0},{1,1,0,0},{0,1,1,0},{1,1,1,1}};
getPath(mat);

}
}

- anaghgg September 24, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
public class PathInMatrix {
    public static boolean utilityPath(int x,int y,int m,int n,int[][] mat,List<List<Integer>> path)
    {
        if(x==m-1 && y==n-1)
        {
            path.add(Arrays.asList(x,y));
            path.forEach((p)->System.out.println(p.get(0)+","+p.get(1)));
            return true;
        }
        if(x>=0 && x<m && y>=0 && y<n && mat[x][y]==1)
        {
            path.add(Arrays.asList(x,y));
            if(utilityPath(x+1,y,m,n,mat,path) || utilityPath(x,y+1,m,n,mat,path))
                return true;
            path.remove(path.size()-1);
        }
        return false;
    }
    public static void getPath(int[][] mat)
    {
        boolean path=utilityPath(0,0,mat.length,mat[0].length,mat,new ArrayList<>());
    }
    public static void main(String[] args) {
        int[][] mat={{1,0,0,0},{1,1,0,0},{0,1,1,0},{1,1,1,1}};
        getPath(mat);

    }
}

- anaghgg September 24, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

public class T2 {

	private static ArrayList<ArrayList<Integer>> twoDimen = new ArrayList<>();

	public static void main(String[] args) {

		init();

		int col = -1;
		int row = -1;

		Stack<Map<Integer, Integer>> result = new Stack<>();
		Map<Integer, Integer> getPrev = new HashMap<>();

		boolean firstRow = true;

		for (int i = 0; i < twoDimen.size(); i++) {
			ArrayList<Integer> getA = twoDimen.get(i);

			for (int j = 0; j < getA.size(); j++) {

				if (getA.get(j) == 1) {

					if (firstRow) {
						row = i;
						col = j;
					} else {
						getPrev = result.peek();

						if (getPrev.isEmpty() || getPrev == null)
							continue;
						else {
							int value = -1;
							if (getPrev.containsKey(i - 1)) {
								value = getPrev.get(i - 1);

								if ((value == j)) {
									for (int k = j; k < getA.size(); k++) {
										if (getA.get(k) == 1) {
											row = i;
											col = k;
										}
									}
									break;
								} else {
									continue;
								}
							}
						}
					}
				}

			}
			firstRow = false;

			Map<Integer, Integer> getOne = new HashMap<>();
			if ((row != -1) || (col != -1))
				getOne.put(row, col);
			result.add(getOne);

		}
		System.out.println(result);
	}

	private static void init() {
		ArrayList<Integer> inner = new ArrayList<>();

		inner.add(1);
		inner.add(0);
		inner.add(0);
		inner.add(0);

		twoDimen.add(inner);
		inner = new ArrayList<>();

		inner.add(1);
		inner.add(1);
		inner.add(0);
		inner.add(0);

		twoDimen.add(inner);
		inner = new ArrayList<>();

		inner.add(0);
		inner.add(1);
		inner.add(1);
		inner.add(0);

		twoDimen.add(inner);
		inner = new ArrayList<>();

		inner.add(1);
		inner.add(1);
		inner.add(1);
		inner.add(1);

		twoDimen.add(inner);
		inner = new ArrayList<>();

	}

}

- mannerh1 October 21, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

const matrixSize = 5;
const dataGenerator = n => {
  const data = [];
  for (let i =0; i < n; i++) {
    const insideData = [];
    for (let i =0; i < n; i++) {
      insideData.push(Math.round(Math.random()));
    }
    data.push([...insideData]);
  }
  return data; 
};
const generateMap = path => {
  path.visited = true;
  if (path.x < matrixSize - 1 && inputData[path.x + 1][path.y] == 1) {
      paths.push(
          {
              x: path.x + 1, y: path.y,
              from: [...path.from, `${path.x},${path.y}`],
              visited: false
          });
  }
  if (path.y < matrixSize - 1 && inputData[path.x][path.y + 1] == 1) {
      paths.push(
          {
              x: path.x, y: path.y + 1,
              from: [...path.from, `${path.x},${path.y}`],
              visited: false
          }
      );
  }
}
const inputData = dataGenerator(matrixSize);
const paths = [{from: [], x: 0, y: 0, visited: false}];
while (paths.filter(path => !path.visited).length) {
  paths.filter(path => !path.visited).forEach(path => generateMap(path));
}
const result = paths.find(
  path => path.x === matrixSize - 1 && path.y === matrixSize - 1);
if (result) {
    console.log("Destination reached and the route is ", result.from);
} else {
  console.log("No route to the destination ");
}
console.log("Here is Input data ", JSON.stringify(inputData));

- sam.varghese October 29, 2020 | 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