From 17dba61d5be033d1b895a0cb110e2e335d9f44eb Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Fri, 15 Nov 2024 22:23:14 +0530 Subject: [PATCH] Create 1574. Shortest Subarray to be Removed to Make Array Sorted --- ...ubarray to be Removed to Make Array Sorted | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 1574. Shortest Subarray to be Removed to Make Array Sorted diff --git a/1574. Shortest Subarray to be Removed to Make Array Sorted b/1574. Shortest Subarray to be Removed to Make Array Sorted new file mode 100644 index 0000000..2e91d52 --- /dev/null +++ b/1574. Shortest Subarray to be Removed to Make Array Sorted @@ -0,0 +1,34 @@ +class Solution { +public: + int findLengthOfShortestSubarray(vector& arr) { + //find first ans last decreasing pair + int first=-1; + int last=-1; + int n=arr.size(); + for(int i=0;iarr[i+1]){ + if(first==-1){ + first=i; + } + last=i; + } + } + if (first == -1) { + return 0; + } +// now find the max len of non decreasing array that does not has these pair + + int ans=min(last+1,n-first-1); + for(int i=0;i<=first;i++){ + for(int j=last+1;j