Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

public class Employee {
private int ID;
private String firstName;
private String lastName;
private Employee manager;
private List<Employee> subordinates;

public Employee(int id, String firstName, String lastName, Employee manager)
{
    this.ID = id;
    this.firstName = firstName;
    this.lastName = lastName;
    this.manager = manager;
    this.subordinates = new ArrayList<Employee>();
}
/***
gettter and setter methods are ommitted 
***/

public void addSubordinate(Employee emp){
  if(emp != null){
     this.subordinates.add(emp);
}
}

public void printSubordinate(){

if(subordinates == null || subordinates.isEmpty()){
System.out.println("There are no subordinates");
}else{
  
 for(Employee e : subordinates){
            System.out.println(e.getFirstName + " " + e.getLastName());     
}
}
}
}

- Anonymous April 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is more of a database schema question, wherein subordinates of a employee is represented as foreign key in the employee table.

Representing in OOP model,
Every employee can have a vector to store references of his subordinates, the only issue with this, to store references of all the subordinates in a vector of employee class it needs all subordinate objects must have been instantiated.

- Vijay Rajanna April 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is the best policy

- Javed April 12, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is the best policy

- Javed April 12, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Data base system are designed to manage large bodies of information in addition the database system must a sure the safty of the information stred and protect them from unauthrised acces

- Javed khan bijnor April 12, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

We can do it by using column constraint in the same table as manager, subordinate will be in same table. In Employee table we will have "MANAGER_ID"(this is manager's id for this employee row) column which will have constraint on "ID" column.

- Varma May 07, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

We can do it by using column constraint in the same table as manager, subordinate will be in same table. In Employee table we will have "MANAGER_ID"(this is manager's id for this employee row) column which will have constraint on "ID" column.

- Varma May 07, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

We can do it by using column constraint in the same table as manager, subordinate will be in same table. In Employee table we will have "MANAGER_ID"(this is manager's id for this employee row) column which will have constraint on "ID" column.

- Varma May 07, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

We can do it by using column constraint in the same table as manager, subordinate will be in same table. In Employee table we will have "MANAGER_ID"(this is manager's id for this employee row) column which will have constraint on "ID" column.

- Varma May 07, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

We can do it by using column constraint in the same table as manager, subordinate will be in same table. In Employee table we will have "MANAGER_ID"(this is manager's id for this employee row) column which will have constraint on "ID" column.

- Varma May 07, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

We can do it by using column constraint in the same table as manager, subordinate will be in same table. In Employee table we will have "MANAGER_ID"(this is manager's id for this employee row) column which will have constraint on "ID" column.

- Varma May 07, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

We can do it by using column constraint in the same table as manager, subordinate will be in same table. In Employee table we will have "MANAGER_ID"(this is manager's id for this employee row) column which will have constraint on "ID" column.

- Varma May 07, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

We can do it by using column constraint in the same table as manager, subordinate will be in same table. In Employee table we will have "MANAGER_ID"(this is manager's id for this employee row) column which will have constraint on "ID" column.

- Varma May 07, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

We can do it by using column constraint in the same table as manager, subordinate will be in same table. In Employee table we will have "MANAGER_ID"(this is manager's id for this employee row) column which will have constraint on "ID" column.

- Varma May 07, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

We can do it by using column constraint in the same table as manager, subordinate will be in same table. In Employee table we will have "MANAGER_ID"(this is manager's id for this employee row) column which will have constraint on "ID" column.

- Varma May 07, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

We can do it by using column constraint in the same table as manager, subordinate will be in same table. In Employee table we will have "MANAGER_ID"(this is manager's id for this employee row) column which will have constraint on "ID" column.

- Varma May 07, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Program should be written in Java/C++ using classes and objects

- abcabc April 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

it is not good,it is a tree traverse problem.

- it is not good,it is a tree traverse problem. April 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

it is not good,it is a tree traverse problem.

- it is not good,it is a tree traverse problem. April 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Why is this a tree traverse problem ?

- SamV April 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Need to maintain a list of Managers and their subordinates responding to each manager.

- abcabc April 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Need to maintain a list of Managers and their subordinates responding to each manager.

- abcabc April 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Need to maintain a list of Managers and their subordinates responding to each manager.

- abcabc April 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Need to maintain a list of Managers and their subordinates responding to each manager.

- abcabc April 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Need to maintain a list of Managers and their subordinates responding to each manager.

- abcabc April 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Need to maintain a list of Managers and their subordinates responding to each manager.

- abcabc April 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Need to maintain a list of Managers and their subordinates responding to each manager.

- abcabc April 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Need to maintain a list of Managers and their subordinates responding to each manager.

- abcabc April 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Need to maintain a list of Managers and their subordinates responding to each manager.

- abcabc April 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Need to maintain a list of Managers and their subordinates responding to each manager.

- abcabc April 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

package emp;

import java.util.HashSet;
import java.util.Set;

public class Employee {

    int id;
    String firstName;
    String lastName;
    Employee manager;
    Set subordinates = new HashSet<Employee>();

    Employee(int id, String firstName, String lastName) {
        this.id = id;
        this.firstName = firstName;
        this.lastName = lastName;
    }

    void addManager(Employee manager) {
        this.manager = manager;
        manager.subordinates.add(this);
    }

    void addSubordinate(Employee subordinate) {
        this.subordinates.add(subordinate);
        subordinate.manager = this;
    }

    void findDetails() {
        if (this.manager != null) {
            System.out.println("Manager is : " + this.manager);
        } else {
            System.out.println("NO manager for " + this);
        }
        if (this.subordinates.size() > 0) {
            System.out.println("***SUB ORDINATES***");
            for (Object subordinate : this.subordinates) {
                Employee emp = (Employee) subordinate;
                System.out.println(emp);
            }
        } else {
            System.out.println("No subordinates for : " + this);
        }
    }

    @Override
    public String toString() {
        return this.id + " : " + this.firstName + "." + this.lastName;
    }

    public static void main(String argc[]) {
        Employee a = new Employee(1, "a", "aa");
        Employee b = new Employee(2, "b", "bb");
        Employee c = new Employee(3, "c", "cc");
        Employee d = new Employee(4, "d", "dd");
        Employee e = new Employee(5, "e", "ee");
        Employee f = new Employee(6, "f", "ff");
        Employee g = new Employee(7, "g", "gg");

        a.addSubordinate(b);
        a.addSubordinate(c);
        b.addSubordinate(e);
        b.addSubordinate(f);
        c.addSubordinate(g);

        a.findDetails();

    }
}

- AnanathaNag KUNDANALA April 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.HashSet;
import java.util.Set;

public class Employee {

    int id;
    String firstName;
    String lastName;
    Employee manager;
    Set subordinates = new HashSet<Employee>();

    Employee(int id, String firstName, String lastName) {
        this.id = id;
        this.firstName = firstName;
        this.lastName = lastName;
    }

    void addManager(Employee manager) {
        this.manager = manager;
        manager.subordinates.add(this);
    }

    void addSubordinate(Employee subordinate) {
        this.subordinates.add(subordinate);
        subordinate.manager = this;
    }

    void findDetails() {
        if (this.manager != null) {
            System.out.println("Manager is : " + this.manager);
        } else {
            System.out.println("NO manager for " + this);
        }
        if (this.subordinates.size() > 0) {
            System.out.println("***SUB ORDINATES***");
            for (Object subordinate : this.subordinates) {
                Employee emp = (Employee) subordinate;
                System.out.println(emp);
            }
        } else {
            System.out.println("No subordinates for : " + this);
        }
    }

    @Override
    public String toString() {
        return this.id + " : " + this.firstName + "." + this.lastName;
    }

    public static void main(String argc[]) {
        Employee a = new Employee(1, "a", "aa");
        Employee b = new Employee(2, "b", "bb");
        Employee c = new Employee(3, "c", "cc");
        Employee d = new Employee(4, "d", "dd");
        Employee e = new Employee(5, "e", "ee");
        Employee f = new Employee(6, "f", "ff");
        Employee g = new Employee(7, "g", "gg");

        a.addSubordinate(b);
        a.addSubordinate(c);
        b.addSubordinate(e);
        b.addSubordinate(f);
        c.addSubordinate(g);

        a.findDetails();

    }
}

- AnanthaNag KUNDANALA April 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

its a composite design pattern question - head first java

- sid April 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about this.. any thoughts??????


import java.util.ArrayList;

public class Employee {
static ArrayList<Employee> al = new ArrayList();
private String id, fname, lname, mgrid;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getFname() {
return fname;
}

public void setFname(String fname) {
this.fname = fname;
}

public String getLname() {
return lname;
}

public void setLname(String lname) {
this.lname = lname;
}

public String getMgrid() {
return mgrid;
}

public void setMgrid(String mgrid) {
this.mgrid = mgrid;
}

public static void main(String[] args) {
// Loading the employees
Employee vo = new Employee();
vo.setFname("EmpFname");
vo.setLname("EmpLname");
vo.setId("1");
vo.setMgrid("100");
al.add(vo);
Employee vo1 = new Employee();
vo1.setFname("EmpFname2");
vo1.setLname("EmpLname2");
vo1.setId("3");
vo1.setMgrid("100");
al.add(vo1);
Employee vo2 = new Employee();
vo2.setFname("EmpLname3");
vo2.setLname("EmpLname3");
vo2.setId("4");
vo2.setMgrid("101");
al.add(vo2);
Employee vo3 = new Employee();
vo3.setFname("EmpLname4");
vo3.setLname("EmpLname4");
vo3.setId("6");
vo3.setMgrid("101");
al.add(vo3);
Employee vo4 = new Employee();
vo4.setFname("EmpLnameMgr");
vo4.setLname("EmpLnameMgr");
vo4.setId("100");
vo4.setMgrid("1000");
al.add(vo4);

showSubordinates("100");// this method shows the subordinates for Mgr ID
// which is passed.

}

public static void showSubordinates(String EmpID) {
boolean flg = false;
for (int i = 0; i < al.size(); i++) {
Employee vo = al.get(i);
if (vo.getMgrid().equals(EmpID)) {
flg = true;
System.out.println("Subordinate for Mgr " + EmpID + " is: "
+ vo.getFname() + ", " + vo.getLname() + ", EmpID: "
+ vo.getId());
}
}
if (!flg) {
System.out.println("No Subordinates found");
}

}

}

- Praveen April 19, 2012 | 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