Pergunta de entrevista da empresa Bloomberg

Given an array of integers, provide an efficient way of finding an integer that appears only once in this array.

Respostas da entrevista

Sigiloso

3 de dez. de 2013

My choice would be using a HashMap So, Traverse through the array, store each element in the array and its value as 1. Now, if you encounter the same element again further in the array, increment the value of the respective key. After the array exhausts, print the keys whose values are 1.

Sigiloso

20 de abr. de 2016

In .NET use Linq: int? answer; try { int answer = value.First ( v => value.Count ==1); } catch (exception e) { //no value appears once. } //If answer is null there are no non repeating integers return answer;