employer cover photo
employer logo

Question d’entretien chez SanDisk

Find the two highest elements in an unsorted array

Réponses aux questions d'entretien

Utilisateur anonyme

23 juill. 2014

Not sure what language this is suppose to be, but: 1) sizeof(arr), which arr is a pointer, is not going to be the size of the in bytes 2) you have the function returning an int *, but there is no return statement, so you are returning garbage 3) why are you comparing arr[i] to arr[0] every time?!? This is a really bad answer.

2

Utilisateur anonyme

7 août 2013

int* two_Largest(int* arr) { int* myArr = new int [2]; myArr[0] = INT_MIN, myArr[1] = INT_MIN; int len = sizeof(arr)/sizeof(int); for(int i =0; iarr[0]) { myArr[1] = myArr[0]; myArr[0] = arr[i]; } else { myArr[1] = arr[i]; } } }