Pergunta de entrevista da empresa Arista Networks

Given a sorted array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. Eg: [0, 1, 2, 3, 4, 6, 7, 8]

Resposta da entrevista

Sigiloso

23 de jul. de 2017

Best Approach is to take xor of all the elements with their indices. For e.g If array is [0,1,2,3,4,6,7,8] then indices are [0,1,2,3,4,5,6,7] take one more with you i.e 8 too Code: C/C++ int x=0; for(int i=0;i

1