Issue in the code for Ques : Finding Element in a Infinite Array

Author: Pratham-0x19Created Dec 10, 2025Updated Jun 22, 2026

If we consider a array : int[] arr = {3, 5, 7, 9, 10, 90,100, 130, 140, 160, 170};

And take target as : int target = 100;

And use the logic given by Kunal Sir to find the chunk which contains the target : `int start = 0; int end = 1;

while(target > arr[end]){ int temp = end + 1; end = end + (end - start + 1) * 2; start = temp; }

return binarySearch(arr,target,start,end);`

where binarySearch() find the Index of the Target

But the main error is that, target = 100 lies in the chunk of index 6 to index 13 using the logic above i.e start = 6 and end = 13. But the array length is 11

And hence it gives a error Index 13 out of bounds for length 11

Source: kunal-kushwaha/DSA-Bootcamp-Java