Skip to content

Latest commit

 

History

History
8 lines (8 loc) · 612 Bytes

note1574.md

File metadata and controls

8 lines (8 loc) · 612 Bytes
  • Type: Two pointers
  • Approach:
    • Find the right most j such that arr[j – 1] > arr[j], if not found which means the entire array is sorted return 0. Then we have a non-descending subarray arr[j~n-1].
    • We maintain two pointers i, j, such that arr[0i] is non-descending and arr[i] <= arr[j] which means we can remove arr[i+1j-1] to get a non-descending array. Number of elements to remove is j – i – 1.
  • Complexity:
    • Time: O(n)
    • Space: O(1)