Page 1 of 1

Dirty-trick and below-the-belt question in real exam. binary search on unsorted array

Posted: Sat Mar 09, 2024 11:18 am
by likejudo

Code: Select all

        // binary search on real exam
        var array = List.of(1,3,2);
        int i = Collections.binarySearch(array,3);
        System.out.println(i);
Since the array is unsorted, I was looking for undefined option - this is also what the Java docs says.
However, the correct answer is '1' as binary search starts at the middle of the array where the correct value happens to be.

Re: Dirty-trick and below-the-belt question in real exam. binary search on unsorted array

Posted: Sun Mar 10, 2024 1:35 am
by admin
Thanks for sharing :thumbup: