Amazon.com

www.amazon.com
Employer Engaged

Interview Question

Software Engineer Interview Seattle, WA

How would you remove common elements from a two arrays.

Answer

Interview Answer

1 Answer

0

input: array1, array2
output: array3, array4

make a hashmap
load array2 into the hashmap
iterate over array1, elements that are not in the hashmap are added to array3

make a hashmap
load array1 into the hashmap
iterate over array2, elements that are not in the hashmap are added to array4

Pavel on May 18, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.