Amazon Interview Question for Software Engineer / Developers






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

import java.util.*;

class Deal {
public static void main(String[] args) {
int numHands = Integer.parseInt(args[0]);
int cardsPerHand = Integer.parseInt(args[1]);

// Make a normal 52-card deck.
String[] suit = new String[]
{"spades", "hearts", "diamonds", "clubs"};
String[] rank = new String[]
{"ace","2","3","4","5","6","7","8",
"9","10","jack","queen","king"};
List<String> deck = new ArrayList<String>();
for (int i = 0; i < suit.length; i++)
for (int j = 0; j < rank.length; j++)
deck.add(rank[j] + " of " + suit[i]);

Collections.shuffle(deck);

for (int i=0; i < numHands; i++)
System.out.println(dealHand(deck, cardsPerHand));
}
}

- codechampion July 10, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static <E> List<E> dealHand(List<E> deck, int n) {
int deckSize = deck.size();
List<E> handView = deck.subList(deckSize - n, deckSize);
List<E> hand = new ArrayList<E>(handView);
handView.clear();
return hand;
}

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

Class Card{
public:

const static int CLUBS=1;
const static int SPADE=2;
const static int HEART=3;
const static int DIAMOND=4;

Card(int suite,int number)
{
(*this).suite=suite;
(*this).number=number;
}
private:
int suite;
int number;
}
#define LOOP(start,end) for(i=start;i<=end;i++)
#define ASSIGN(n,i,start) mydeck[i]=Card(n,i-start)

Class Deck{
public :
Card[52] mydeck;
Deck()
{
int i=0;
LOOP(0,12)
ASSIGN(Card.CLUBS,i,0);
LOOP(13,25)
ASSIGN(Card.SPADES,i,13);
LOOP(26,38)
ASSIGN(Card.HEARTS,i,26);
LOOP(39,51)
ASSIGN(Card.DIAMOND,i,39);
}
void shuffle(){
int i=0,j=0;
LOOP(0,51){
j=random(i,51);
swap(j,i);}
}

void swap(int i,int j){
Card tmp=mydeck[i];
mydeck[i]=mydeck[j];
mydeck[j]=tmp;
}
}

- Anand Rai September 11, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

where is ur deal.

- rohit April 24, 2008 | Flag
Comment hidden because of low score. Click to expand.
-1
of 0 vote

you guys are doing a huge assumption mistake: that we are talking about a regular deck. What if we're talking about a monopoly deck? or some special deck of other special cards?

- Dominator December 09, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 0 votes

It could also be the deck of a ship tiled entirely by playing cards. However, I think that's unlikely. :)

We could write code for a pinochle deck too, some of it will be in common.

- Josh March 31, 2008 | Flag


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