Using pointers
\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
\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```swift []\nclass Solution {\n    func findLengthOfShortestSubarray(_ arr: [Int]) -> Int {\n        guard !arr.isEmpty, arr.count > 1 else { return 0 }\n        var left = 0, right = arr.count - 1\n        while left < arr.count - 1 && arr[left] <= arr[left+1] {\n            left += 1\n        }\n        if left == arr.count - 1 { return 0 }\n\n        var minLength = right - left\n        print(minLength)\n        while left >= 0 {\n            while arr[right - 1] <= arr[right] && (arr[left] <= arr[right-1] || left == 0) {\n                right -= 1\n            }\n            let rightBorder = arr[left] <= arr[right] ? -1 : 0\n            minLength = min(minLength, right - left + rightBorder)\n            left -= 1\n        }\n        return minLength\n    }\n}\n```
['Swift']