Amazon Interview Question for Software Engineer / Developers






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

I have given a sample start.. feel free to add to it.

package google;

import java.util.ArrayList;
import java.util.Random;

public class Cards {

private class card {
char suite;
Integer number;
}

private ArrayList<card> cardArray = new ArrayList<card>();

public Cards() {
// TODO Auto-generated constructor stub

char Suite = 'S';

switch (Suite) {

case 'S': {
for (int i = 1; i <= 10; i++) {
card c = new card();
c.number = i;
c.suite = 'S';
cardArray.add(c);
}

card A = new card();
A.number = 'A';
A.suite = 'S';
cardArray.add(A);

card J = new card();
J.number = 'J';
J.suite = 'S';
cardArray.add(J);

card Q = new card();
Q.number = 'Q';
Q.suite = 'S';
cardArray.add(Q);

card K = new card();
K.number = 'K';
K.suite = 'S';
cardArray.add(K);
Suite = 'C';
}
case 'C': {
for (int i = 1; i <= 10; i++) {
card c = new card();
c.number = i;
c.suite = 'C';
cardArray.add(c);
}

card A1 = new card();
A1.number = 'A';
A1.suite = 'C';
cardArray.add(A1);

card J1 = new card();
J1.number = 'J';
J1.suite = 'C';
cardArray.add(J1);

card Q1 = new card();
Q1.number = 'Q';
Q1.suite = 'C';
cardArray.add(Q1);

card K1 = new card();
K1.number = 'K';
K1.suite = 'C';
cardArray.add(K1);
Suite = 'H';
}
case 'H': {
for (int i = 1; i <= 10; i++) {
card c = new card();
c.number = i;
c.suite = 'H';
cardArray.add(c);
}

card A2 = new card();
A2.number = 'A';
A2.suite = 'H';
cardArray.add(A2);

card J2 = new card();
J2.number = 'J';
J2.suite = 'H';
cardArray.add(J2);

card Q2 = new card();
Q2.number = 'Q';
Q2.suite = 'H';
cardArray.add(Q2);

card K2 = new card();
K2.number = 'K';
K2.suite = 'H';
cardArray.add(K2);
Suite = 'D';
}
case 'D': {
for (int i = 1; i <= 10; i++) {
card c = new card();
c.number = i;
c.suite = 'D';
cardArray.add(c);
}

card A2 = new card();
A2.number = 'A';
A2.suite = 'D';
cardArray.add(A2);

card J2 = new card();
J2.number = 'J';
J2.suite = 'D';
cardArray.add(J2);

card Q2 = new card();
Q2.number = 'Q';
Q2.suite = 'D';
cardArray.add(Q2);

card K2 = new card();
K2.number = 'K';
K2.suite = 'D';
cardArray.add(K2);
break;
}

}

}

public void display(){
for(int i = 0; i < cardArray.size() ; i++){
if(cardArray.get(i) != null){
if(cardArray.get(i).number <= 10){
System.out.println(cardArray.get(i).suite+ " " + cardArray.get(i).number);
}
else{
System.out.println(cardArray.get(i).suite+ " " + (char)cardArray.get(i).number.intValue());
}
}
}
}

public void shuffle(){

for(int i = 0; i < 52; i++ ){
System.out.println("");
Random rand = new Random();

int r = i + ((Math.abs(rand.nextInt())) % 52-i);

//System.out.println(i + " "+ r);
card temp = cardArray.get(i);
card temp2 = cardArray.get(r);

if(temp.number <= 10){
System.out.print(temp.suite+ " " + temp.number);
}
else{
System.out.print(temp.suite+ " " + (char)temp.number.intValue());
}

if(temp2.number <= 10){
System.out.print(" " +temp2.suite+ " " + temp2.number);
}
else{
System.out.print(" "+temp2.suite+ " " + (char)temp2.number.intValue());
}

cardArray.add(i, cardArray.get(r));
cardArray.add(r, temp);
}
//System.out.println("");
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Cards obj = new Cards();
//obj.display();
obj.shuffle();
//obj.shuffle();
//obj.display();
}

}

- Java Coder October 10, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Crap.....How do u want us to read this BullShit

- Sathish November 22, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i back up Satish. wtf

- Anonymous January 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i back up Satish. wtf

- Anonymous January 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

0.. 53 can be interpreted in presentaion layer as 54 cards.

Java coder fail in class design.

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

0.. 53 can be interpreted in presentaion layer as 54 cards.

Java coder fail in class design.

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

Asshole... providing logic is much more easier for u as well as us...

- anonymous... October 30, 2010 | 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