This repository consists of the code samples, assignments, and notes for the Java data structures & algorithms + interview preparation bootcamp of WeMakeDevs.
The previous code wouldn't give solution if the index end becomes greater than the actual length. Lets say in
int[] arr = {3, 5, 7, 9, 10, 90, 100, 130, 140, 160, 170}; There are 11 elements in the list. Thus, from index 0 to 10. Lets say we go from 0,1 to 2,5 and then to 6,11 index. Note that in the first two cases the previous code would have given the correct solution but in the last case of 6,11 the code will throw an error because index 11 is not in the array. This code helps to fix that issue.
fix: ArrayIndexOutOfBoundsException
The previous code wouldn't give solution if the index end becomes greater than the actual length. Lets say in int[] arr = {3, 5, 7, 9, 10, 90, 100, 130, 140, 160, 170}; There are 11 elements in the list. Thus, from index 0 to 10. Lets say we go from 0,1 to 2,5 and then to 6,11 index. Note that in the first two cases the previous code would have given the correct solution but in the last case of 6,11 the code will throw an error because index 11 is not in the array. This code helps to fix that issue.