[Java] O(n). Clean code and easier to understand than other solutions. Beats 100%
\n# Approach\n3 cases:\n- subarray in beginning\n- subarray at the end\n- subarray in middle\n\nCheck for longest sorted array from beginning and from end, and 
\n# Approach\n3 cases:\n- subarray in beginning\n- subarray at the end\n- subarray in middle\n\nCheck for longest sorted array from beginning and from end, and find min_subarray_len to remove.\nThen for the third case, check for case if subarray is in mid. check till where we can have arr[i] <=\n\t\t// arr[j], where 0<=i<=left, j>= right\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(n)$$ \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n\n# Code\n```\nclass Solution {\n   public int findLengthOfShortestSubarray(int[] arr) {\n\t\tint left = 0, right = arr.length - 1, min_subarray_len = arr.length - 1;\n\n\t\twhile (left < arr.length - 1 && arr[left] <= arr[left + 1])\n\t\t\tleft++;\n\n\t\twhile (right > 0 && arr[right] >= arr[right - 1])\n\t\t\tright--;\n\n\t\tmin_subarray_len = Math.min(right, arr.length - left - 1); // subarray in end or start\n\n\t\t// check for case if subarray is in mid. check till where we can have arr[i] <=\n\t\t// arr[j], where 0<=i<=left, j>= right\n\n\t\tint i = 0, j = right;\n\n\t\twhile (i <= left && j < arr.length && i<j) {\n\t\t\tif (arr[i] <= arr[j]) {\n\t\t\t\tmin_subarray_len = Math.min(min_subarray_len, j - i - 1);\n\t\t\t\ti++;\n\t\t\t} else {\n\t\t\t\tj++;\n\t\t\t}\n\t\t}\n\n\t\treturn min_subarray_len;\n\t}\n}\n```
['Java']