Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

I don’t know much about the first question, but you can use a Binary Search Tree.

For second question, one can definitely use a “Binary Heap”( a heap-ordered complete binary tree ). Whenever you add a new member into the organization, you move up the member, so that the member(parent) is larger than its children. Whenever you delete a member, you move down. At any point you move up/down to restore the heap ordering - (organizational hierarchy)

- Snehasish Barman January 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

For the first part, do you think a hashed array of linked lists could work. The lists contain employee details which are hashed by manager name. So insertion, deletion of employee under a manager is simple.

- doomguy January 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Maybe you can, but there is a major flaw here as you are hashing by manager name. Here “key” is the “name”, so you might land up with lots of duplicate keys. Duplicate keys are always bad.
You may want to hash it by using a unique number such as employee id...

- Snehasish Barman January 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hi Snehasish Barman,

I think instead of a Binary Heap, something like a N-Way Heap is better as each node can have many childs.

- Srikant Aggarwal January 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hi Srikant,

You can have a N-way Heap and by doing that i assume you want to achieve constant-time performance and add more complexity. But the catch is that a “Binary Heap” will give you logarithmic performance for most operations. Most of the time you will perform insert and delete operations on the heap which are very efficient using binary. If we can sacrifice small performance for complexity/maintainability, its better for all of us.

- Snehasish Barman January 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hey guys...
good discussion... I'd like to jump in...
if we have an N-way heap the complexity would remain logarithmic. The only thing is before it was Log-base-2 and now it would be log-base-(max n).... n is a constant and hence in terms of complexity we could any time change it to base-2 and ignore the constant generated.... so we're all fine

- p February 19, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

enum EMPLOYEE_TYPE
{
CEO,
VP,
MANAGER,
EMPLOYEE,
};

typedef struct employee
{
enum EMPLOYEE_TYPE type;
char *name;
struct employee *lead;
struct employee *employee;
struct employee *co_emp;
}employee;

typedef struct node
{
char *name;
struct node *next;
}node;

node *get_employees(employee em)
{
node *head, *current_employee;
employee *child = em->employee;
while(child != NULL)
{
node *temp = (node *)malloc(sizeof(node));
if(head == NULL)
head = temp;
else
current_node->next = temp;
current_node = current_node->next;
child = child->co_emp;
}
return head;
}

- Srikant Aggarwal January 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can we use a binary tree, with each node has one pointer to first child and second to the sibling. This will make deletion and addition in the hierarchy very fast.
And we can have a trie to keep name or id of employee to keep pointer of those employee node in the tree, a hash table will also work.

- abhishekatuw January 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In its most basic form, this looks like a typical "composite" design pattern.

en.wikipedia.org/wiki/Composite_pattern

- ViX July 03, 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