Pray you dont get this in interview - O(N) solution
Approach and Intuition explained in code comments\nSince we are removing a subarray and ensure that remaining\nsubarray is in non-decreasing order, we have to c
# Approach and Intuition explained in code comments\nSince we are removing a subarray and ensure that remaining\nsubarray is in non-decreasing order, we have to check the following\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n  public int findLengthOfShortestSubarray(int[] arr) {\n    int n = arr.length;\n    int l = 0;\n    // Find non-decreasing sub array from left side including left most element\n    while (l < (n - 1) && arr[l] <= arr[l + 1]) {\n      l++;\n    }\n\n    // if non-decreasing sub array from left side went all the way to the right,\n    // then whole array is already non-decreasing. \n    // return 0 cause nothing needs to be deleted\n    if (l == n - 1)\n      return 0;\n    \n    // Find non-decreasing sub array from right side including right most element\n    int r = n - 1;\n    while (r > 0 && arr[r] >= arr[r - 1]) {\n      r--;\n    }\n\n    // Connect two subarrays and find the "connecting" elements that make both\n    // subarrays on left and right non-decreasnig when combined\n    /*\n                                              /\n                                            /      \n                                          /  \n               /              / --       /\n            /  L  \\         /      \\__ /\n         /          \\ ___ /         R\n      /\n      i                             j\n\n      You need to "connect" i and j pointers\n\n\n                                             /\n                                            /      \n                                          /  \n                                         /\n                                    __ /\n         /                          R\n      /\n      i                             j\n\n      All the elements in the middle would be removed \n      to make remaining sub array non-decreasing\n\n      Use two pointer approach i, j\n      i++ when arr[i] <= arr[j]\n      j++ when arr[i] > arr[j]\n    */\n    int result = Math.min(n - l - 1, r);\n    int i = 0;\n    while (i <= l && r < n) {\n      if (arr[r] >= arr[i]) {\n        result = Math.min(result, r - i - 1);\n        i++;\n      } else {\n        r++;\n      }\n    }\n\n    return result;\n  }\n}\n```
['Two Pointers', 'Java']