Find the answer to the current element
int cur = AToi [ A [ i ] ] ; int l = mp [ cur ] [ 0 ] ; int r = mp [ cur ] [ 1 ] ; if ( l >= 0 && r < N ) { m = min ( ans [ l ] , ans [ r ] ) + 1 ; } else if ( l < 0 && r < N ) { m = ans [ r ] + 1 ; } else if ( l >= 0 && r >= N ) { m = ans [ l ] + 1 ; }