Condition to check if the length of the array is odd
if ( ( n & 1 ) != 0 ) { left = ( int ) a [ n / 2 ] ; right = ( int ) b [ n / 2 ] ; ans = right - left + 1 ; } else { left = ( ( int ) a [ n / 2 ] + ( int ) a [ n / 2 - 1 ] ) ; right = ( ( int ) b [ n / 2 ] + ( int ) b [ n / 2 - 1 ] ) ; ans = right - left + 1 ; } Console . WriteLine ( ans ) ; }