Remove digits, retaining greater number Introduction

This challenge consists in finding the greatest number removing y digits from the original number n which has x digits.

Assuming y=2 n=5263 x=4, the possible numbers removing y=2 digits are:

[52, 56, 53, 26, 23, 63]


So, the greatest number is 63 which must be the output for this example.



Another logic would be: for each y, search from left to right the digit which right next digit is greater, then remove it, else when no match, remove the last y-digits.

Using y=3 n=76751432 x=8 to explain:

y=3
76751432
-^------ remove 6 because right next 7 is greater

y=2
7751432
---^--- remove 1 because right next 4 is greater

y=1
775432
-----^ the search failed, then remove last y digits

result = 77543


Both methods explained above works.. of course, you can use another method too :)

Challenge

The number n won't have more than 8 digits, and y will always be greater than zero and lower than x.

To avoid strict input format, you can use the values: y n x the way you prefer: as parameters in function, raw input, or any other valid way. Just don't forget to say how you did that in your answer.

The output should be the result number.

This is code-golf, the shortest answer in bytes wins.

Example Input and Output

Again: you do not need to be too strict :)

4 1789823 7 -&gt; 983
1 54132 5   -&gt; 5432
3 69314 5   -&gt; 94
2 51794 5   -&gt; 794


Edit

I changed the input order to reflect the fact that some of you may not need the x value to solve the problem. x is now an optional value.
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