Amazon | SDE1 | Bangalore | Mar 2019 [Offer]

Status: Software Developer 1.5 yrs experience
Location: Bangalore
Position: SDE at Amazon

Recruiter reached out to me a week before and then scheduled onsite interviews.

Round 1:

  1. Print all the subsets of a given set.
  2. Given a 2D matrix of integers. One can move in all 8 directions, so find the maximum size cluster/component of the same number in the matrix which are adjacent to each other. The problem was sort of similar to https://leetcode.com/problems/number-of-islands. I solved it using DFS. I chose a number and ran dfs on it and my dfs terminated once I reached to an unequal number.
visited[1000][1000];

int dx = [0, -1, -1, -1, 0, 1, 1,1];
int dy = [1, 1, 0, -1, -1, -1, 0, 1];

int dfs(int r, int c, int src){
/*base conditions*/
int count = 1;
for(int i=0; i<8; i++){
dr = r+dx[i];
dc = c+dy[i];
if(dr>=0 && dr<R && dc>=0 && dc<C){
if(!visited[dr][dc] && mat[dr][dc]==src){
visited[dr][dc]=1;
count += dfs(dr, dc, src);
}
}
}
return count;
}
  1. Buy and Sell stock problem IV

Round 2:

  1. Given a tree, convert into circular linked list.
  2. Given a directed graph, a src and a dst, print all the paths from src to dst
  3. min number of swaps required to sort an array
  4. Project discussions, challenging thing I have done etc

Round 3:

  1. Project discussions, my past experiences, what mistakes I have done, what kind of decisions I have taken etc.
  2. Given an array of strings, every element of the array represents a word, you need to print all the anagrams of a word together in the array.
    words = [abc, def, sir, race, fed, cab, efd, care, irs, ris]
    ans = [abc, cab, def, fed, efd, sir, irs, ris, race, care]

Round 4:

  1. General discussion about projects, roles that I played in my previous companies, questions relevant to 14 principles of Amazon.
  2. Buy and sell stock problem I
  3. A infinite stream of integers is coming, you need to return 10 minimum elements. I solved it using priority_queue(max heap). I always maintained the size of the priority queue to be always equal to 10. Whenever I inserted an element into the queue, I would pop up all the elements until the size is 10.
/*let us suppose the stream has a definite size for a moment*/
stream[n]= {...};
priority_queue<int> pq;
for(int i=0; i<n; i++){
	pq.push(stream[i]);
	while(pq.size()>10)
		pq.pop();
}
/*return pq elements*/

Result: Received the offer.

Comments (2)