Easy Two Pointer  Solution with explanation
\n# Intuition\n- The problem requires finding the shortest subarray to remove so that the remaining elements form a non-decreasing sequence. The initial idea is
\n# Intuition\n- The problem requires finding the shortest subarray to remove so that the remaining elements form a non-decreasing sequence. The initial idea is to identify the longest non-decreasing prefix and suffix, as they indicate portions of the array that may not need modification.\n\n# Approach\n1. Identify Prefix: Start from the beginning and find the longest non-decreasing subarray (left).\n2. Identify Suffix: Start from the end and find the longest non-decreasing subarray (right).\n3. Calculate Minimum Removal:\nCompute the minimum removal based on removing from either end (arr.length - left - 1 or right).\nUse a two-pointer technique to check if merging parts of the prefix and suffix can yield a shorter removal.\n4. Return Result: Return the minimum length of the subarray that needs to be removed.\n\n# Code\n```python3 []\nclass Solution:\n    def findLengthOfShortestSubarray(self, arr):\n        left = 0\n        while left + 1 < len(arr) and arr[left] <= arr[left + 1]:\n            left += 1\n        if left == len(arr) - 1:\n            return 0\n        \n        right = len(arr) - 1\n        while right > left and arr[right - 1] <= arr[right]:\n            right -= 1\n        \n        result = min(len(arr) - left - 1, right)\n        \n        i, j = 0, right\n        while i <= left and j < len(arr):\n            if arr[j] >= arr[i]:\n                result = min(result, j - i - 1)\n                i += 1\n            else:\n                j += 1\n        \n        return result\n\n```\n```java []\nclass Solution {\n    public int findLengthOfShortestSubarray(int[] arr) {\n        int left = 0;\n        while (left + 1 < arr.length && arr[left] <= arr[left + 1]) {\n            left++;\n        }\n        \n        if (left == arr.length - 1) {\n            return 0;\n        }\n        \n        int right = arr.length - 1;\n        while (right > left && arr[right - 1] <= arr[right]) {\n            right--;\n        }\n        \n        int result = Math.min(arr.length - left - 1, right);\n        \n        int i = 0;\n        int j = right;\n        while (i <= left && j < arr.length) {\n            if (arr[j] >= arr[i]) {\n                result = Math.min(result, j - i - 1);\n                i++;\n            } else {\n                j++;\n            }\n        }\n        \n        return result;\n    }\n}\n```
['Array', 'Two Pointers', 'Java', 'Python3']