Skip to content

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

@CodeXDev25

Description

@CodeXDev25

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions