kunal-kushwaha / DSA-Bootcamp-Java

This repository consists of the code samples, assignments, and notes for the Java data structures & algorithms + interview preparation bootcamp of WeMakeDevs.
https://www.youtube.com/playlist?list=PL9gnSGHSqcnr_DxHsP7AW9ftq0AtAyYqJ
16.07k stars 10.45k forks source link

Code correction request for file lectures/10-binary search/code/src/com/kunal/InfiniteArray.java #1251

Closed KartikC137 closed 5 months ago

KartikC137 commented 5 months ago

Location of the code file: "lectures/10-binary search/code/src/com/kunal/InfiniteArray.java" This question is covered in video #15 [Binary Search Interview Questions - Google, Facebook, Amazon] , question 5 [ time stamp : 1:28:00]

Error: The code throws "java.lang.ArrayIndexOutOfBoundsException" error if the index of target value is greater than the mid value

For instance : If given array = {3, 5, 7, 9, 10, 90, 100, 130, 140, 160, 170} and target = 100 or any value after 130 but works fine if target is any value less than 90 Screenshot from 2024-01-16 17-44-21 Screenshot from 2024-01-16 17-45-08

Request:

I do not know how to fix this, I tried using chatgpt, but it does not help. I Reckon the error is due to Condition given for while loop in line 17.

KartikC137 commented 5 months ago

I was wrong here , there cannot be out of bound error for infinite array, as the solution is given to a hypothetical question.