If current number is the maximum obtained so far
if ( ( newstr . ToString ( ) . CompareTo ( ans . ToString ( ) ) > 0 && ans . Length == newstr . Length ) newstr . Length > ans . Length ) { ans . Append ( newstr ) ; } } return ; } StringBuilder x = new StringBuilder ( newstr . ToString ( ) + str [ index ] ) ;