Amazon Interview Question for SDE-2s


Country: United States
Interview Type: In-Person




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

Can you please elaborate the functionality of lockers ?

- Kaushik Lele October 30, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

When a customer selects for a delivery to be made-

1) They should be assigned a locker number closest to his zip code.
2) They should be allowed to cancel a locker delivery until the order has been shipped.
3) You can assume that you have several concurrent requests coming in. When I asked for the hourly/monthly requests we should expectedly be processing, I was told to assume it is tight but not extraordinary. However, the design should allow to scale up.
4) Service should be highly available.

I was also asked to think about how an update would be made to make a locker available when an order is picked up.

- teli.vaibhav October 30, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

But what is locket meant for ? What is its relation of locker with delivery ?
What is criteria to decide id locker is closest to zip code?

- Kaushik Lele October 31, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hey Is this a coding question or architectural design question which includes database interactivity with backend logic

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

Is this a coding question using any data structure or an architectural design question?

- HPV121 November 04, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Suppose we have a city of a given length and width which we can represent as a grid (int[][]) and a list of locker points (x and y coordinates), then we can pre-compute the distance of the closest locker to each point in the grid:

private static int[][] getLockerDistanceGrid(int cityLength, int cityWidth, List<Point> lockerPositions) {
        int[][] grid = new int[cityLength][cityWidth];
        for (int row = 0; row < grid.length; row++) {
            for (int col = 0; col < grid[0].length; col++) {
                grid[row][col] = findClosestManhattanDistance(getCoordinate(row), getCoordinate(col), lockerPositions);
            }
        }
        return grid;
    }

    private static int getCoordinate(int zeroBasedPosition) {
        return zeroBasedPosition + 1;
    }

    private static int findClosestManhattanDistance(int x, int y, List<Point> lockerPositions) {
        int closesDistance = Integer.MAX_VALUE;
        for (Point p : lockerPositions) {
            int distance = Math.abs(x - p.x) + Math.abs(y - p.y);
            closesDistance = Math.min(distance, closesDistance);
            // we know we can't get better than 0 distance
            if (closesDistance == 0)
                return closesDistance;
        }
        return closesDistance;
    }

    static class Point {
        int x, y;
        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

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

Data-structure 1 -  ZipGraph - represents zips in a state
Data-structure 2 - Node{
	represents node of above graph i.e. Data-structure 1 ,
	Node {
		zip code,
		H : heap data-structure of LockObject
	}
	
	LockObject{
		LockNumber,
		status (1/0) 1=> available 0 => not available},
		zip code
	}

}
	
assign Locker number (orderID)- 
 
	for(Node node : for all Node which have zip code belongs to customer’s zip code & find all adjacent zip codes using Data-structure 1){
		lock( Node );
		LockObject lockObj = Node.H.getRoot()
		if( lockObj != null ){
			lockObj . status = 0;
			assign(lockObj.LockNumber , orderID)
			rearrange the heap H
			unlock(Node);
			break;
		}
		unlock(Node);
		
	}
}

cancel Locker(lockObject){

	Node node = Traverse Data-structure 1 (Graph) to find zip code
	lock(node){
		lockerObject = search(node.H, lockObject)
		lockerObject.status=1;
		rearrange the heap
	}

}

make available(lockObject){

	cancel Locker(lockObject)
}

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

Data-structure 1 -  ZipGraph - represents zips in a state
Data-structure 2 - Node{
	represents node of above graph i.e. Data-structure 1 ,
	Node {
		zip code,
		H : heap data-structure of LockObject
	}
	
	LockObject{
		LockNumber,
		status (1/0) 1=> available 0 => not available},
		zip code
	}

}
	
assign Locker number (orderID)- 
 
	for(Node node : for all Node which have zip code belongs to customer’s zip code & find all adjacent zip codes using Data-structure 1){
		lock( Node );
		LockObject lockObj = Node.H.getRoot()
		if( lockObj != null ){
			lockObj . status = 0;
			assign(lockObj.LockNumber , orderID)
			rearrange the heap H
			unlock(Node);
			break;
		}
		unlock(Node);
		
	}
}

cancel Locker(lockObject){

	Node node = Traverse Data-structure 1 (Graph) to find zip code
	lock(node){
		lockerObject = search(node.H, lockObject)
		lockerObject.status=1;
		rearrange the heap
	}

}

make available(lockObject){

	cancel Locker(lockObject)
}

- thakur.871 January 06, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

this is supposed to be a system design question.

- dada November 22, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

dfsdfdsf

- dfsdfdfd August 30, 2017 | 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