Iterate over the array arr [ ] to store length of decreasing sequence that can be obtained at every index in the left array
for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i ] < a [ i - 1 ] ) { left [ i ] = left [ i - 1 ] + 1 ; } } if ( n > 2 ) {