Hey all. I am struggling with this exercise from my book. My problem is that I can't even run the program, because it gives meException in thread "main" java.lang.ArrayIndexOutOfBoundsException: 13
at domashno.ten.longestSortedSequence(ten.java:37)
at domashno.ten.main(ten.java:17)public static void main(String[] args) { int[] arr = {3, 8, 10, 1,9, 14, -3, 0, 14, 207, 56, 98, 12}; longestSortedSequence(arr); System.out.println(longestSortedSequence(arr)); } public static int longestSortedSequence(int[] arr) { int beg=0; int end=0; int count=0; for(int i=end;i<=arr.length-1;i++){ int begTemp=0; int endTemp=0; int tempCount=0; for(int j=i+1;j<=arr.length;j++){ begTemp=arr[end]; if(arr[end]<=arr[j]){ tempCount++; } if(arr[end]>arr[j]){ endTemp=arr[j-1]; } } if(count<tempCount){ count=tempCount; end=endTemp; beg=begTemp; } } int length=0; for(int k=arr[beg];k<=arr[end];k++){ length++; } return length; } }