Amazon Interview Question


Country: United States




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

First of all, what is the purpose of the data structure ?
If getting "no of student" and "no of subject" is the goal, we can use two maps, one with <stduent id, no_of_subject> pair as an element and the other one with <subject id, no_of_students> pair as an element.

However, if the goal is to retrieve students taking a specific subject or retrieve subjects that a specific student is taking, I would use two maps (or hashtable):
- stduent hash map: key => stduent id , value => list of subject ids(either linked list or std::vector)
- subject hash map: key=> subject id, value=> list of student ids(either linked list or std::vector)

- hankm2004 April 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If I understand it correctly, Given input is about stundent and the subjects which are attended by a particular student. And If focus is to get the query done faster, then a map can be created with string as Key and List as value. Now when any student-subject input is received, get the data using student as key and update the value list with the subject, do the same for subject as key and update the value list containing number of students attending it.

When query is done to find how many subjects are attended by a particular student named "ABC" , then get the corresponding list from map suing this student name as key and return the size of list.

- OTR April 20, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If problem is just about finding "no of students per subject" and "no of subjects per student". You just need to maintain counters.

- Harsh April 25, 2014 | 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