Pergunta de entrevista da empresa Tableau Software

Given an unsorted array of integers, output an array containing the numbers in the original array that appear an odd number of times. What is the runtime of your process?

Respostas da entrevista

Sigiloso

23 de dez. de 2015

If space is a constraint: Iterate over the array, inserting each int into a set. Delete from set if encountered int is present. Thus at the end of array iteration, the set contains only odd-counted ints. Output set's values. O(n) average time, O(k) extra space where k is number of distinct elements with odd frequency of occurrence.

7

Sigiloso

10 de dez. de 2015

Use a Hashmap to store array values and their number of appearance. Iterate through hashmap and output only keys whose values are odd. O(n).

2