+ 1
Can anyone help me with this code?
The findElement function was supposed to return 4 but it's returning -1. https://code.sololearn.com/cbzZQA8QZXIu/?ref=app
4 Answers
+ 1
For binary search, the elements must be in sorted order..!
+ 1
I watched a YouTube explanation of this problem and it says this uses binarysearch cuz a part of the array is sorted so it does binary search on that part!Jayakrishnađźđł
+ 1
Ok.
index 4<4 is stoping loop so < instead of <= in while(start <= end) solve issue. but it may be only for this case.
+ 1
//while (start < end) {
while (start <= end) {
I checked only this array example but it can search all elements