Amazon Interview Question for Software Engineer / Developers

Country: United States
Interview Type: Phone Interview

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

I think it should be something along these lines.

class SoccerLeague {
  public enum Result {

  List<Team> teams;

  public SoccerLeague (int numTeams) {
    teams = new ArrayList<Team>();

  void addTeam (String name) {
    teams.add(new Team(name));

  public Team getTeam(String a) {
    for (Team t : teams) {
      if( {
        return t;
    return null;

  void processMatchResult(String a, String b, Result result) {
    Team first;
    Team second;
    if((first = getTeam(a)) == null ) return;
    if((second = getTeam(b)) == null ) return;
    first.played ++;
    second.played ++;
    if(result == Result.WIN_BY_FIRST) {
      first.points += 3;
      second.lost ++;
    else if (result == Result.WIN_BY_SECOND) {
      second.points += 3;
      first.lost ++;
    else {
      first.drawn ++;
      second.drawn ++;
      first.points ++;
      second.points ++;
  void printResult(String a) {
    Team team = getTeam(a);
    if(team == null) return;
    System.out.format("%4s %6d %3d %4d %5d %6d\n",,
        team.played, team.won, team.lost, team.drawn, team.points);

  int getPoints (String a) {
    Team team = getTeam (a);
    if(team == null) return 0;
    return team.points;
  class Team {
    String name;
    int points;
    int played;
    int won;

    int lost;
    int drawn;

    public Team(String A) { = A;
      points = 0;
      played = 0;
      won = 0;
      lost = 0;
      drawn = 0;
  public static void main (String[] args) {
    SoccerLeague sl = new SoccerLeague(3);
    sl.processMatchResult("A", "B", Result.WIN_BY_FIRST);
    sl.processMatchResult("B", "C", Result.WIN_BY_FIRST);
    sl.processMatchResult("C", "A", Result.DRAWN);
    sl.processMatchResult("A", "B", Result.WIN_BY_SECOND);
    sl.processMatchResult("B", "C", Result.WIN_BY_SECOND);
    sl.processMatchResult("C", "A", Result.WIN_BY_FIRST);
    System.out.format("Team Played Won Lost Drawn Points\n");
    int points;
    points = sl.getPoints("A");
    System.out.println("Team A points = " + points);
    points = sl.getPoints("B");
    System.out.println("Team B points = " + points);
    points = sl.getPoints("C");
    System.out.println("Team C points = " + points);


- famee December 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 votes

Why make 2 methods for Win by first or second - you can just have First Team Won and change the order while setting the input. :)
So win and draw are 2 results and you can swap teams so that the first team wins

We can also add a bracket creating feature

- Aztec warrior January 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
of 0 vote

lets take matrix (n*n) for each match, summary/ result will be stored in matrix,
lets say a won match against b ,tie against c. then matrix[a][b] += 3, matrix[a][c] +=1,
Finally we can have total points of each team..

Am i right... Plz gve your comments

- ranganath111 January 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.

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