Qualtrics interview question

Given two arrays, write a function that will return an array with the common values between the arrays.

Interview Answer

Anonymous

22 Jul 2016

Write a function taking in two arrays, store the contents of the second into a hash set for O(1) lookup time. Iterate through the first array, and for every value, check if it's in the set you created. If so, put it in the result array and then return it at the end. If you used the hash set properly, the Big O is O(n). If you kept the second array as an array, Big O is O(n^2).

1