Amazon Interview Question for Software Engineer / Developers

Country: United States
Interview Type: In-Person

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

You need to figure out what objects would be relevant.

Off the bat I see:
-Cell object which could be extended to Ant, Food,Water.
-Board Object, which consists of cells
-Player object, which are the attributes both players have when playing this game.
-Game Manager, essentially holds all the rules and validates moves

So the Cell essentially just holds what type of cell it is. Nothing more nothing less.

The Board class could be set up as matrix and inside each index of the matrix is a Cell object that represents the appropriate cell. You'd also need methods such as move cell, which would move the appropriate cell to specified location.

This brings me to the next object, the Game Manager. The Game Manager would look at whether or not the moves are legal. If they're illegal then it'd notifhy the board object. If legal then it'd notify the board object. Things like that...

The Player class would have a constructer which assigns a username to each player and maybe a uniquieID. You'd have methods like move, skip, send message, etc...

The list truly does go on for a long while. The biggest thing here is that you need some basics, and then once you get the basics, you can add even more functionality.

- Frank March 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
of 1 vote

Above approach looks fine .. but there is problem with cell object inheriting from ant,food and water ... if ant enters into a food cell than that cell should become an ant cell ... but we can't do this since the food cell is already inherting from food cell and we can't make it inherit from ant cell dynamically ...
solution would be to create a cell class and each cell would have a state/strategy names ant , food water and depending upon the condition we can dynamically chage the state of cell. This state object will handle all the scenarios for that particular cell type.

- naveen October 26, 2013 | Flag
Comment hidden because of low score. Click to expand.
of 0 vote

class antGame has following member variables

1>movement is a enum or macro which have 4 possible value left,right,up and down;and nextCell is the type of cell like food, water and ant;
2> method move(string movement); Where the user can make the ant move to the cell specified by the movement value of nextcell as parameter.
3> method nextCell(string Cell,string movementl); will accept Cell as the current cell and next cell as the movement parameter and returns the output of the movement.
4> method nextCellContains(string Cell,string movement); accepts the same parameters but returns what is the content of the adjacent cell.
5> has a class Object ant(may be an independent class), which needs to be created by constructor and destroyed not only by destructor but also the dissolve movement.
6> Object ant has to be singleton and is accessible to two different antGame object.

The list will go on and on.. after discussion.. But really good question..

- hprem991 February 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

could be related to the "game of life"
search for conways-game-of-life-in-java in technicalypto site

- goutham467 February 26, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

I am trying to understand how two players will this game ?

- Rahul July 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

state patter for cells

- archit September 02, 2017 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


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


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