Java | 100% faster | With explanation
As the question clearly states that we can only remove one subarray our answer should be one of the following 3 possiblities - \n1) The answer is formed from th
As the question clearly states that we can only remove one subarray our answer should be one of the following 3 possiblities - \n1) The answer is formed from the beginning and we discard all the elements after the first decreasing element we find.\n2) The answer is formed from the end, i.e, we get an increasing sequence once we delete some numbers from the front.\n3) The answer is formed by removing some elements from the middle.\n\nSo I\'ve started with two indices firstLast and lastFirst which gives me the first non-increasing index from front and back.\nminLength is initialized so that it captures the possibilities 1 or 2.\nNow to check possibility 3, we have to see which index from the front can be used to form an increasing array with the tail.\n```\nclass Solution {\n    public int findLengthOfShortestSubarray(int[] arr) {\n        int firstLast=0,lastFirst=arr.length-1;\n        for(;firstLast<arr.length-1;firstLast++){\n            if(arr[firstLast]>arr[firstLast+1]) break;\n        }\n\t\t//Base case for a non-decreasing sequence\n        if(firstLast==arr.length-1) return 0;\n        for( ;lastFirst>0;lastFirst--){\n            if(arr[lastFirst]<arr[lastFirst-1]) break;\n        }\n\t\t//Possibilities 1 or 2 as mentioned above\n        int minLength=Math.min(arr.length-firstLast-1,lastFirst);\n        for(;firstLast>=0;firstLast--){\n            for(int i=lastFirst;i<arr.length;i++){\n                if(arr[firstLast]>arr[i]) continue;\n                minLength = Math.min(minLength,i-firstLast-1);\n                break;\n            }\n        }\n        return minLength;\n    }\n}\n```
['Java']