Java Count from head and tail
\n    public int findLengthOfShortestSubarray(int[] arr) {\n        int n = arr.length, l = 0, r = n - 1;\n        while(l + 1 < n && arr[l] <= arr[l + 1]) l++;
```\n    public int findLengthOfShortestSubarray(int[] arr) {\n        int n = arr.length, l = 0, r = n - 1;\n        while(l + 1 < n && arr[l] <= arr[l + 1]) l++;  // find increasing subarray [0..l]\n        if(l == n - 1) return 0;\n        while(r - 1 >= 0 && arr[r - 1] <= arr[r]) r--; // find increasing subarray [r..n-1]\n        int fr = 0, res = Math.min(n - l - 1, r);\n        while (fr <= l && r < n) {  // find max combination \n            while(fr <= l && arr[fr] <= arr[r]) fr++;\n            res = Math.min(res, r - fr);  // remove [fr...r - 1];\n            while(fr < n && r < n && arr[fr] > arr[r]) r++;\n        }\n        return res;\n    }\n```
[]