Pergunta de entrevista da empresa FactSet

If you have a sorted array that is initialized with size 100, the values stored would be for example 1, 2, 3,.... ect. Describe an algorithm that would check if there is a duplicate number and if so return it.

Respostas da entrevista

Sigiloso

3 de mar. de 2015

this seems not using the sorted condition, there can be better solution

Sigiloso

19 de mar. de 2015

This is a sorted array. So the duplicates, if present must be side by side. We can use XOR operation to find this. public class DuplicateElementInArray { public static int checkDup(int array[]) { for(int i=0; i

Sigiloso

8 de jun. de 2015

if the values are 1..100 with one of them repeated, add them up and subtract sigma(1,100) = O(n)

1

Sigiloso

27 de mar. de 2015

Perform binary search where A[mid] == A[mid-1] || A[mid]==A[mid+1] with care for Array index bounds. This will be done in log n