Super Simple Sliding Window Solution Java/C (O(n))
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n1. Find the already sor
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Find the already sorted suffix (using r index) (if r reaches 0 that means the whole array is already sorted and rmvLength=0)\n2. Start from the beginning of the array (l = 0) and move right while maintaining a sorted prefix. At each step:\n    - Move r forward as needed to ensure the prefix element arr[l] can be merged with the suffix starting at r.\n   - Update rmvLength to the smaller of its current value and the number of elements removed (r - l - 1).\n\n# Example\n**arr = [1, 2, 3, 10, 4, 2, 3, 5]**\n1. Start from the end(r idx ) and find the longest sorted suffix. Here, [2, 3, 5] starting at index(r) = 5.\n2. Expand prefix and try merging:\n    - l = 0 (arr[0] = 1): 1 <= 2 (arr[r]), so merging is possible. Calculate removals as r - l - 1 = 5 - 0 - 1 = 4. Update rmvLength to 4.\n    - l = 1 (arr[1] = 2): 2 <= 2 (arr[r]), so merging is possible. Calculate removals as 5 - 1 - 1 = 3. Update rmvLength to 3.\n    - l = 2 (arr[2] = 3): 3 <= 2 fails, so move r to 6 (now arr[6] = 3), and now 3 <= 3 works. Calculate removals as 6 - 2 - 1 = 3, so rmvLength remains 3.\n    - l = 3 (arr[3] = 10): 10 > 3 fails. Move r to 7 (arr[7] = 5), but 10 > 5 still fails.\n3. final result = 3\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public int findLengthOfShortestSubarray(int[] arr) {\n        int l = 0, r = arr.length - 1;\n        while (r > 0 && arr[r] >= arr[r - 1]) {\n            r--;\n        }\n        int rmvLength = r;\n        while (l < r && (l == 0 || arr[l] >= arr[l - 1])) {\n            while (r < arr.length && arr[l] > arr[r]) {\n                r++;\n            }\n            rmvLength = Math.min(rmvLength, r - l - 1);\n            l++;\n        }\n        return rmvLength;\n    }\n}\n```\n```c []\nint findLengthOfShortestSubarray(int* arr, int arrSize) {\n    int l = 0, r = arrSize - 1;\n    while (r > 0 && arr[r] >= arr[r - 1]) {\n        r--;\n    }\n    int rmvLength = r;\n    while (l < r && (l == 0 || arr[l] >= arr[l - 1])) {\n        while (r < arrSize && arr[l] > arr[r]) {\n            r++;\n        }\n        rmvLength = (rmvLength < r - l - 1) ? rmvLength : r - l - 1;\n        l++;\n    }\n    return rmvLength;\n}\n```
['Two Pointers', 'C', 'Java']