Open AmiteshVerma24 opened 1 year ago
yea ,thank you AmiteshVerma for giving explanation and cleared my doubt.
Code link: Question link
This question was very well explained by Kunal however there is small issue with it. While finding the range we are checking whether
arr[end] < target
however when we try to search for an element which is present towards the end of the array there is a case whenend > arr.length - 1
which results in Array Index Out Of Bound Exception to fix it we can use try-catch block.I have attached my solution below Updated code Thanks
Code link: Question link
This question was very well explained by Kunal however there is small issue with it. While finding the range we are checking whether
arr[end] < target
however when we try to search for an element which is present towards the end of the array there is a case whenend > arr.length - 1
which results in Array Index Out Of Bound Exception to fix it we can use try-catch block.I have attached my solution below Updated code