Amazon Interview Question for SDE-2s


Country: India




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

So basically they just want you to break this down into basic data types and functions you would have. This could be done in a variety of ways here is a quick stab at it:

public Board {
	int activePlayers;
	player [] players;
	Deck deck;
	
	// functions
	deal -> deals out all cards from deck to players
	find_winner -> uses card classes compare to see who won hand
	player_lost -> set player as lost if out of cards
	player_won -> if only 1 player left, they won
}

public Deck {
	Card [] cards;

	//functions
	remove card -> removes card from deck like pop in queue/stack
	add card -> add card to bottom like push on queue 
}

public Card{
	// where Suit is an enum containing {spade, diamond, heart, club}
	Suit suit;
	int num;

	//functions
	compare -> compares 2 cards based on the game, depending if suit matters
}

public Player{
	Card [] hand;
	bool lost;

	//functions
	add to hand -> add to card at end like push on queue
	flip from hand -> take card from top like pop on queue/stack
	player lost -> mark player as out of cards, lost
}

With these basic elements you could code in the functionality of the game, I imagine they would be looking for correct syntax (which I didn't really do). But most likely they are looking that you can break things down into an OOP way.

- Im a Wienner! August 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The board should probably also have functions for if the game was a tie to do war, and to return the cards to the winning players hand. But we will just say that is all incorporated in the illustrious "find_winner" function :D

- Im a Wienner! August 09, 2013 | 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