Amazon Interview Question
Software Engineer in TestsNull array
Two element array
Three element array with following cases:
All three same inputs
Two inputs same and the third one is largest or smallest(test for all three positions)
All three different elements with right answer in each of the slots
Test one case with all negative numbers and a mix of negative, positive and zero
Test array greater than 3 and keep the last number as the third largest.
Similar to above case but keep the first element as the largest
Try non numeric array like an array of strings
i have written a method that returns the third largest integer in a given array.
- mdrigalos May 31, 2011public int thirdLargest(int arr[n]){
int j=0;
int max=arr[0];
int temp[n];
if(n<3)
return null;
for(i=0;i<=n;i++) {
if(arr[i]>max){
max=arr[i];
temp[j]=max;
j++;
}
}
return temp[j-2];
}