Java 100% with Explanation - Time O(n), Space - O(1)
Algorithm\n The logic is to find the point from left to right where we see a dip, and from right to left we see a raise\n We initialize two pointer left and rig
**Algorithm**\n* The logic is to find the point from `left` to `right` where we see a dip, and from right to left we see a raise\n* We initialize two pointer `left` and `right`\n* Run a while loop where `left` pointer is less that the length of the array and the `left` index item in the array is less that the immediate right element. Move the `left` pointer until then\n* Run another loop from `right` end of the array until the index is greater than the `left` index and decrement the `right` pointer till then.\n* Get the minimum from `left` and `right` pointer\n* Now we have to loop through 0 to `left` and `right` to `arr.length` to find the minimum length of the subarray\n* If `arr[right] >= arr[left]` then update the result with `min` and increment `left` otherwise increment the `right` pointer\n\n```\nclass Solution {\n    public int findLengthOfShortestSubarray(int[] arr) {\n        int n = arr.length;\n        int left = 0;\n        int right = n-1;\n        \n        while (left < n-1 && arr[left] <= arr[left+1]) left++;\n        if (left == n-1) return 0;\n        \n        while (right >= left && arr[right] >= arr[right-1]) right--;\n        if (right == 0) return n-1;\n        \n        int result = Math.min(n-1-left, right);\n        \n        int i=0;\n        int j = right;\n        \n        while (i <= left && j < n){\n            if (arr[j] >= arr[i]){\n                result = Math.min(result, j-i-1);\n                i++;\n            }\n            else{\n                j++;\n            }\n        }\n        return result;\n    }\n}\n```\n
[]