Amazon | SDE II | Telephone | Seattle | Reject
Anonymous User
1559

After telephone screen by Recuriter I chose to give an attempt at SDE II. I been in IT for 17 years and still wanted to do a SDE II so I can align myself with Amazon standards. Prepared for about 4 weeks. First Coding Interview book started with Leet but it was out of order then I chose AlgoMonster and completed all topic used by Amazon. Prepared 2 examples for each LP. Attended yesterday .

  1. Tell me about yourself.
  2. Toughest Technical Project
  3. Coding Round https://leetcode.com/problems/random-pick-with-weight
  4. I have not seen this problem but I came up with Algo and it seemed solid O(2n) so not bad. But after an hour got a message they are not proceeding this time .

Following is C# code I have written. I chose to fill in 100 Items array with Probablities for each Index and picked a random Item. Which seemed correct. Word random and percentage was conflicting may be I messed up may be I said Sorry I am nervous that interviewer didnt like. So many questions. Either way. You all give enough time and do all the problems. Manytimes and dont take the prep easily . You got to invest yourself this is no easy task. Good Luck youall

public class Solution {
	private int[] items;
	private int totalSum;
	private int[] prefixSums;

	public Solution(int[] w)
	{
		this.prefixSums = new int[w.Length];
		this.items = w;
		int prefixSum = 0;
		for (int i = 0; i < w.Length; ++i)
		{
			prefixSum += w[i];
			this.prefixSums[i] = prefixSum;
		}
		this.totalSum = prefixSum;
	}

	public int PickIndex()
	{
		int[] randomPicks = new int[100];
		int counter = 0;
		for (int i = 0; i < items.Length; i++)
		{
			 
			var count = ((double)items[i] / (double)this.totalSum) * 100;
			 
			for (int j = counter; j < counter + count; j++)
			{
				randomPicks[j] = i;
			}
			counter = counter + (int)count;
		}
		Random r=new Random();
		return randomPicks[r.Next(0, 99)];

	}
}

/**
 * Your Solution object will be instantiated and called as such:
 * Solution obj = new Solution(w);
 * int param_1 = obj.PickIndex();
 */
Comments (2)