Amazon Interview Question for Software Engineer / Developers






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

1. Find box with fewest items f.
2. Divide each box count by f.
- The result becomes how many items you return per pick
- The remainder represents how many picks you return one additional item

Example 1.
BoxCounts: 3, 25, 92
box1 = 1, remainder 0.
box2 = 8 remainder 1.
box3 = 30 remainder 2.

1,9,31
1,8,31
1,8,30

public class Box
{
	public static int smallestBox;
	bool isInitialized;
	int count;
	int countPerTurn;
	int remainder;
	
	public Box(int numItems)
	{
		Box.smallestBox = numItems < ProportionalPickBox.smallestBox ? numItems : Box.smallestBox;
		this.count = numItems;
	}
	
	public int PickCount
	{
		get
		{
			if (!isInitialized)
			{
			   this.countPerTurn = count/smallestBox;
			   this.remainder = count % smallestBox;
			}
			int val = countPerTurn + Math.Max(0,remainder--));
			count -= Val;
			return val;
		}
	}
}

public void Main()
{
	Box[] boxes = new Box[3];
	boxes[0] = new Box(72);
	boxes[1] = new Box(39);
	boxes[2] = new Box(3);
	
	for (int v=0; v < Box.SmallestBox; v++)
	{
		Console.Write("Step " + v.ToString());
		Console.Write("\t Pick " + boxes[0].PickCount.ToString())
		Console.Write("\t Pick " + boxes[1].PickCount.ToString())
		Console.Write("\t Pick " + boxes[2].PickCount.ToString())
	}
}

- Anonymous June 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

can u explain the logic again?

- seeker7 July 07, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can u please elaborate the logic ??

- ravikant July 24, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

shouldn't it be that u sum the amount of each box and pick an item from a box with probability (box amt)/total amount ?

- Anonymous July 01, 2010 | 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