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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
likejudo
Posts: 26
Joined: Sun Feb 18, 2024 7:21 pm
Contact:

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

Post 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.

admin
Site Admin
Posts: 10065
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Thanks for sharing :thumbup:
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 229 guests