Condition to check if the length of the array is odd
if ( ( n & 1 ) != 0 ) { left = a . get ( n / 2 ) ; right = b . get ( n / 2 ) ; ans = right - left + 1 ; } else { left = ( a . get ( n / 2 ) + a . get ( n / 2 - 1 ) ) ; right = ( b . get ( n / 2 ) + b . get ( n / 2 - 1 ) ) ; ans = right - left + 1 ; } System . out . println ( ans ) ; }