[Java][2 ms] Beats 100% - simple two pointers solution O(N)
\nclass Solution \n{\n    public int findLengthOfShortestSubarray(int[] arr) \n    {\n        int left = 0, right = arr.length - 1;\n        \n        while(rig
```\nclass Solution \n{\n    public int findLengthOfShortestSubarray(int[] arr) \n    {\n        int left = 0, right = arr.length - 1;\n        \n        while(right > 0 && arr[right - 1] <= arr[right])\n            right--;\n        \n        //whole array sorted\n        if(right == 0)\n            return 0;\n        \n        //arr[right...arr.length - 1] is sorted, set the result by removing the arr[0...right -1]\n        int result = right;\n\n        while(left < right)\n        {\n            //Move the window such that arr[left] <= arr[right]\n            while(right < arr.length && arr[left] > arr[right])\n                right++;\n            \n            //Remove the subarray between left and right index and update the minimum \n            result = Math.min(result, right - left - 1);\n            \n            //The subarray arr[0...left] is sorted, then remove the right side completely and update result if minimum\n            if(arr[left] <= arr[left + 1])\n                result = Math.min(result, arr.length - (left + 2));\n            else\n                break;\n\n            left++;\n        }\n        \n        return result;\n    }\n}\n```
['Two Pointers', 'Java']