If ans [ i ] is equal to - 1
if ( ans [ i ] == - 1 ) { if ( smaller . Count > 0 ) { ans [ i ] = smaller [ smaller . Count - 1 ] ; smaller . RemoveAt ( smaller . Count - 1 ) ; } else if ( greater . Count > 0 ) { ans [ i ] = greater [ greater . Count - 1 ] ; greater . RemoveAt ( greater . Count - 1 ) ; } } }