employer cover photo
employer logo

Sollicitatievraag bij SanDisk

Find the two highest elements in an unsorted array

Antwoorden op sollicitatievragen

Anoniem

23 jul 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

Anoniem

7 aug 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]; } } }