employer cover photo
employer logo
employer logo

SanDisk

Acquired by WD

Is this your company?

SanDisk interview question

Find the two highest elements in an unsorted array

Interview Answers

Anonymous

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

Anonymous

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