We have assumed that x1 will be left and x2 right but if not then we just swap them
if ( x1 > x2 ) { swap ( x1 , x2 ) ; } int Occ_Till_Right = pref [ x2 - 1 ] ; int Occ_Till_Left = pref [ x1 ] ; ans = ans + ( Occ_Till_Right - Occ_Till_Left ) ; } } return ans ; }