Traverse the array and if any negative element found then update the length of longest subarray with the length of left and right subarray
for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] < 0 ) { len = max ( len , max ( N - i - 1 , i ) ) ; } } return len ; }