Amazon Interview Question for Data Engineers


Team: none
Country: india
Interview Type: Written Test




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

Union : (Assuming order of element doesn't matter )

Put all the elements of both arrays in HashSet , now Hashset will have union of both the arrays.

Intersection: (Assuming order of element doesn't matter )

Put all the elements of one array in HashSet.
Iterate over other array and check whether element is present HashSet created in previous step if yes include it in intersection result else ignore.

- Ankit Tomar October 04, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Ankit Tomar's idea will not generally work - because arrays are not guaranteed to be unique. Of Course with unique array - where all elements are different it will work, but that is now as trivial as intersection and union of sets.

Solution to this problem is to imagine the generalised set operations.
Suppose an element valued "e" has count "count_a" in the "a" array or list, and "count_b" in the "b" array or list.

count of element "e" in the intersection of a,b will be defined as:

min( count_a, count_b)

count of element "e" in the union of a,b will be defined as:

max( count_a, count_b)

This generalised algorithm now can be used to Union/Intersection.You can generalised this to even find out set minus.

- NoOne October 04, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

@NoOne : It was mentioned in Question - "elements of the two given array may be repeated but cannot be repeated in union and intersection array."
so i proposed the above solution. :)

- Ankit Tomar October 04, 2019 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Ah I see. Then your solution works, and the question is not even a question, sadly. :(

- NoOne October 07, 2019 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Good point from both of you guys!

- aacom007 October 19, 2019 | 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