Remove digits, retaining greater number
MATL, 10 bytes

-jowXncUX&gt;


This uses version (9.2.1) of the language/compiler, which is earlier than this challenge.

It takes three inputs from stdin in this order: string length, number of removed characters, string.

Example

&gt;&gt; matl
 &gt; -jowXncUX&gt;
 &gt; 
&gt; 7
&gt; 4
&gt; 1789823
983


EDIT: Try it online! (the code in the link has XN instead of Xn to conform to changes in the language after this challenge; also, o is not needed anymore)

Explanation

(This still costs 2 bytes more than it should due to Octave's and Matlab's nchoosek function behaving differently. Fixed in the next release of the compiler.)

-        % implicitly input two numbers, and subtract them
jo       % input string, and convert to ASCII codes
wXn      % swap inputs. Generate all combinations, each in a row
c        % convert to char array
U        % convert each row to a number
X&gt;       % get maximum. Implicitly display




Answer to original challenge (stricter input requirements): 16 bytes

jYbZ)b-wowXncUX&gt;


Uses current version (9.2.1) of the language/compiler.

Example

&gt;&gt; matl jYbZ)b-wowXncUX&gt;
&gt; 4 1789823 7
983


Explanation

(This should have been 4 bytes less, but I need that wow...c because Octave's nchoosek function, unlike Matlab's, doesn't work with character input. Will be fixed for next release of the compiler.)

j              % input string
YbZ)           % split at spaces into strings
b-             % subtract first and third (1-digit) strings
wow            % convert middle string into ASCII codes
Xn             % get all combinations, each in a row
c              % convert to char array
U              % convert each row to a number
X&gt;             % get maximum. Implicitly display