I have an array contains 10 integer values. Now I want to find out the
second highest number.I should not use any java API. This question was asked by one interviewer to me. He wants the logic.And his requirement is, I should not traverse through the the entire elements. Is there any way where we can achieve the result without traversing?
Travesing means going through all the elements in the array. I thought for long time.Finally I gave up. If any one can explain, it would be nice. And also I asked about Sorting. He does not want the array to be sorted.
I have an array contains 10 integer values. Now I want to find out
Share
No, it’s completely impossible. If you don’t look at all the data, you can’t possibly know the second highest value.
You don’t have to sort all the data, of course, which may be what your interviewer meant – but you do need to look at every element at least once. Every element has the possibility of changing the result, so needs to be examined.