Amazon Interview Question for SDE-2s


Country: India
Interview Type: In-Person




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

We can decorate(Decorator_pattern) each furniture with the type(wood, metal etc.)

- Brandy May 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

The only use-case is decorate furniture with metal or wood or something else and applied different tests based on type.
but not like decorate furniture with wood and then with metal etc..
So do we really need decorator?

- amidala.shiva November 06, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

decorate patten used when we want to attach properties or enhancement an object dynamically. here we know in the begining what to design.

- Anonymous January 28, 2015 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

enum FurnitureType {
	WOOD, METAL;
}

abstract class Furniture {
	FurnitureType furnitureType;
	FurnitureTest furnitureTest;

	public Furniture(FurnitureType furnitureType, FurnitureTest furnitureTest) {
		this.furnitureType = furnitureType;
		this.furnitureTest = furnitureTest;
	}

	public boolean testFurniture() {
		return furnitureTest.testFurniture();
	}

}

interface FurnitureTest {
	public boolean testFurniture();
}

class WoodFurnitureTest implements FurnitureTest {
	public boolean testFurniture() {
		/*
		 * Test code goes here
		 */
		return true;
	}
}

class MetalFurnitureTest implements FurnitureTest {
	public boolean testFurniture() {
		/*
		 * Test code goes here
		 */
		return true;
	}
}

class Chair extends Furniture {
	public Chair(FurnitureType furnitureType, FurnitureTest furnitureTest) {
		super(furnitureType, furnitureTest);
	}
}

class Table extends Furniture {
	public Table(FurnitureType furnitureType, FurnitureTest furnitureTest) {
		super(furnitureType, furnitureTest);
	}
}

class TestClient {
	public static void main(String[] args) {

		WoodFurnitureTest woodFurnitureTest = new WoodFurnitureTest();
		MetalFurnitureTest metalFurnitureTest = new MetalFurnitureTest();

		// create wood chair
		Chair woodchaChair = new Chair(FurnitureType.WOOD, woodFurnitureTest);

		// create metal chair
		Chair metalChair = new Chair(FurnitureType.METAL, metalFurnitureTest);
	}
}

- Sniga May 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The solution should be open for extension. How would you test a furniture made of both wood & steel? If you add a new furniture, without code change how it will support test?

- geekyjaks May 25, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Furniture shouldn't have a dependency on WoodenFurnitureTest. For creating any furniture you need to put a "Test" for it.

It shouldn't be so tight coupled with Test

- Anonymous June 01, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

public interface Material{
	public void setTestFixture(TestFicture fixture);
}
public interface TestFixture {
	public void test();
}
public interface Furniture {
	public void setMaterial(Material m);
}
-----------------------------------
public class ChokingTestFixture implements TestFixture {
	public void test() {...}
}
public class FireTestFixture implements TestFixture {
	public void test() {...}
}
-----------------------------------


/* Similarly Wood can be formed. If we make a abstract class as Material, then even this setTestFixture() code need not to be duplicated */
public class Metal implements Material {
	TestFixture fixture;
	public void setTestFixture(TestFixture fixture) {
		this.fixture = fixture;
	}
}
------------------------------------
/* Similarly Chair,Table,Sofa can be constructed as follows*/
public class Chair implements Furniture {
	public void setMaterial(Material m) {

	}
}

- Rajib Banerjee June 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

interface IMaterialValidatable
{
void validateQuality();
}

public abstract class Material implements IMaterialValidatable
{

}

class Wood extends Material
{
public void validateQuality()
{
// validate quality of wood material
}
}

class Metal extends Material
{
public void validateQuality()
{
//Validate metal quality;
}
}

abstract class Furniture
{
Material[] materials;

Furniture(Material[] materials)
{
this.materials = materials;
}

void evaluateQuality()
{
for(Material material : materials)
{
material.validateQuality();
}
}
}

class Chair extends Furniture
{
}

- Anonymous June 01, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

how about something along the lines of..
pardon my syntax... mix of C++ and C#

interface Furniture
{
  // returns bool as test fail or pass
   virtual bool TestTheFurniture( TestData* tdata) = 0;
}

interface TestData
{
    // ???
}

class WoodenTestData : TestData {}
class MetalTestData : TestData {}

class WoodenFurniture : Furniture
{
   bool TestTheFurniture(WoodTestData* wd) {}
}

class MetalFurniture : Furniture
{
   bool TestTheFurniture(MetalTestData* wd) {}
}

- codethecode August 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Strategy Pattern should be good fit for this design problem.

- getPDat October 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{{
interface Furniture {
void test();
}

abstract class AbstractFurniture {
Material material;
AbstractFurniture(Material m) {
this.material = m;
}
void test() {
material.testStrength();
}
}

class Chair extends AbstractFurniture{}
class Table extends AbstractFurniture{}

interface Material {
void testStrength();
}

class wood implements Material {
void testStrength() {
testfire();
}
}
}}

- anon January 25, 2015 | 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