Pergunta de entrevista da empresa NVIDIA

Problem Statement : In an array of numbers, the difference between two consecutive numbers is 1, ( i.e. can be +1 or -1). You have to find a key value from the array without implementing linear search.

Respostas da entrevista

Sigiloso

9 de mar. de 2015

int main() { int a[10]={5,6,7,6,5,6,7,8,9,8}; int i,n,found=0,diff; scanf("%d",&n); i=0; while(i<10) { diff=n-a[i]; if(diff==0) { printf("Index: %d\n",i); found=1; break; } else { i=i+abs(diff); } } if(found==0) printf("Element Not found\n"); return 0; }

1

Sigiloso

6 de jul. de 2014

Pretty Easy...!

6