Check whether an array can be made strictly increasing by removing at most one element | Function to find if is it possible to make the array strictly increasing by removing at most one element ; Stores the count of numbers that are needed to be removed ; Store the index of the element that needs to be removed ; Traverse the range [ 1 , N - 1 ] ; If arr [ i - 1 ] is greater than or equal to arr [ i ] ; Increment the count by 1 ; Update index ; If count is greater than one ; If no element is removed ; If only the last or the first element is removed ; If a [ index ] is removed ; If a [ index - 1 ] is removed ; Driver Code
function check ( arr , n ) { var count = 0 ; var index = - 1 ; for ( i = 1 ; i < n ; i ++ ) { if ( arr [ i - 1 ] >= arr [ i ] ) { count ++ ; index = i ; } } if ( count > 1 ) return false ; if ( count == 0 ) return true ; if ( index == n - 1 index == 1 ) return true ; if ( arr [ index - 1 ] < arr [ index + 1 ] ) return true ; if ( arr [ index - 2 ] < arr [ index ] ) return true ; return false ; } var arr = [ 1 , 2 , 5 , 3 , 5 ] ; var N = arr . length ; if ( check ( arr , N ) ) document . write ( " " ) ; else document . write ( " " ) ;