Pregunta de entrevista de Tableau Software

Why do you want to join Tableau? Find the smallest unique integer in a random integer array with possible duplicates.

Respuestas de entrevistas

Anónimo

1 oct 2015

make a hash map, first go through each number and put it in hash map. Then go through each number again, check the value in hash map, if it is equal to 1, then compare this with min(you can make it Integer.max_val at the beginning), and keep updating this min.

3

Anónimo

3 ago 2015

Sort the array and loop through the sorted array. Return the element once you find it's not same as it's previous element or it's next element. N(log(N) + O(N) complexity

1

Anónimo

27 sep 2016

Sorting is not the best answer -- the sort itself is O(n log n). HashMap is better (can use a bool instead of int as the value though -- just need to know if it's dupe or not, so no need to update the value M times. :)

Anónimo

16 sep 2015

By set I mean, map, you need to keep track of how many times each element occurs. To find smallest element, you only need to consider the elements that only occurs once.

Anónimo

16 sep 2015

May not be the best solution. I think you can use a set to keep track of the unique integers in this array, and then iteratively visit the elements in the set to find the smallest element. O(N). S(N).