Amazon Interview Question
Testing / Quality Assurances1)find largest element in n-1. Again find largest element excepting that element in n-2. total comparisons 2n-3 i.e, O(n)
2)maintain 2 variables lar and secLar and in single loop find second largest by comparing largest with array element and secLar with lar. best case comparisons n-1, worst case 2(n-1) {increasing array} still it is O(n)
3)Order statistic blum et. al , find nth largest element in O(n).
Array size should be between 2 and int max size.(depends on int size, assuming int array)
1.Array containing at least two elements.
- Algorithmist February 08, 20112.arrays having the same data type as that in function.
3.Array with only one dimension no two dimensional arrays.
4.Arrays containing only primitive data .Array should be containing pointers to some other elements.
5.All Arrays with size >=2 but having all indexes being initialized or being static in nature.for e.g. int a[5]={1}; would be an invalid input array to this function.