Amazon Interview Question for Software Engineer / Developers


Country: Canada
Interview Type: Phone Interview




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

I will assume that deck is a standard 52-card set, like you in the game of black jack.

Please refer to the Cracking the coding interview 8.1

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

I would first clarify how the games are played, find the user scenarios and user stories

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

yearky mara hoeche
boka*****

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

Assuming:-

Suit:
Club = 0
Diamond = 1
Heart = 2
Spade = 3

Color:
Black = 0
Red = 1

class Cards {
private:
	int m_suit ;
	int m_rank ;

public:
	Cards ( int r, int s ) {
		m_rank = r ;
		m_suit = s ;
	}

	int getRank ( ) { 
		return m_rank ;
	}

	int getSuit() {
		return m_suit ;
	}

	int getColor ( int suit ) {
		return ((1 == suit) || (2 == suit))? 1 : 0 ;
	}

	string toString (int rank) {
		string val ;
		switch (rank) {
			case 1 :
					val = "Ace" ;
					break ;
			.....
			.....
			case 10:
					val = "Jack" ;
					break ;
			case 11:
					val = "Queen" ;
					break ;
			case 12:
					val = "King" ;
					break ;
			default:
					break ;
		}
		return val ;
	}
}

class CardDeck{
private:
	Card[] m_deck ;
	int m_numCards ;
public:
	CardDeck() {
		m_deck = new Card[52] ;
		initCards() ;
	}

	void initCards() {
		int idx = 0 ;
		for ( int rank = 1; rank <= 13; rank++ ) {
			for ( int suit = 0; suit < 4; suit++ ) {
				m_deck[index] = new Card(rank,suit) ;
				index++ ;
			}
		}
		m_numCards = 52 ;
	}

	int getSizeOfDeck () {
		return m_numCards ;
	}

	Card deal () {
		if ( 0 == m_numCards )
			return NULL;
	
		m_numCards-- ;
		return m_deck[m_numCards] ;
	}

	void shuffle() {
		for ( int next = 0; next < m_numCards-1; next++ ) {
			int rdm = myRandom(i, m_numCards-1) ;
			Card temp = m_deck[next] ;
			m_deck[next] = m_deck[rdm] ;
			m_deck[rdm] = temp ;
		}
	}

	static int myRandom ( int low, int high ) {
		return (int) ( (high+1-low) * Math.random() + low ) ;
	}
}

By using these classes, implement for the card games like BlackJack,...

- R@M3$H.N December 31, 2014 | 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