Amazon Interview Question for SDE-2s


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
1
of 3 vote

A very very very vague question. Can you please specify when Amazon said : "best" what did they mean? Example : One can buy 450 Nano cars for the price of one Rolls Royce.
That is best or RR is best?

- NoOne October 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

i'm assuming we're trying to spend the least amount of money on toys so all the kids get to play.

this can be solved with recursion. so:

findLowestPrice(toyList, numKids) {
    //missing stop conditions
    toy = toyList.pop();
    priceIfToyIsNotUsed = findLowestPrice(toyList, numKids);
    priceIfToyIsUsed = findLowestPrice(toyList, numKids - toy.maxKids);
    if (priceIfToyIsNotUsed > priceIfToyIsUsed + toy.price) {
        solution.push(toy); //global var
        return priceIfToyIsUsed + toy.price;
    }
    return priceIfToyIsNotUsed;
}

- MaryJane October 29, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you give the full code including the stop condition

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

i'm assuming we're trying to spend the least amount of money so that all the kids get to play - per shop.
it can be solved by recursion each time taking one toy out of the list and deciding whether it should or shouldn't be in the solution based on whether toy.price + getCheapestPrice(remainingToys, remainingKids - toy.maxKids) > getCheapestPrice(remainingToys, remainingKids)

- netta October 29, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we sort the toys list based on the price/maxChildren in ascending order and can start picking the toys till we all the children have something to play with a few edge cases to be handled

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

public class ShoppingToyComparator implements Comparator<Shop> {

	@Override
	public int compare(Shop o1, Shop o2) {
		int result = 0;
		int i = 0;
		while (result == 0) {
			Toy t1 = o1.getToys().get(i);
			Toy t2 = o2.getToys().get(i);
			result = t1.getPrice() - t2.getPrice();
			if (result == 0) {
				result = t2.getMaxChildren() - t1.getMaxChildren();
			}
			i++;
		}
		return result;
	}

}

- Ambuj Tailang January 30, 2017 | 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