Remove K Digits

Remove K Digits

Time Limit: 1.0 s

Memory Limit: 64.0 MB

Little Jack loves playing with numbers. Recently, he learned about programming and was super excited to find out that strings can represent really big numbers!

Now that Jack is mixing his love for numbers with his new programming skills, he has a fun challenge ahead. Given a large non-negative integer num represented as a string, he wants to remove exactly k digits from it. But there’s a catch—Jack wants the resulting number, after removing those digits, to be the largest possible.

Can you help Little Jack decide which digits he should remove to achieve the largest possible number?

Input format:

Input starts with \(T\) (\(T \le 100\)), the number of cases to check. For each case,

  • The first line contains 2 integers, \(N\) and \(k\) (\(0 \le k \le N \le 100\)), where \(N\) is the length of num, and \(k\) is the number of digits to be removed.
  • The second line contains the number num as a string.

Output format:

Print the largest possible number obtained after removing \(k\) digit.

Sample Input:

2
5 5
54231
5 2
54231

Sample Output:

0
543

Information

ID
1006
Difficulty
6
Category
Greedy Click to Show
Tags
(None)
# Submissions
63
Accepted
9
Accepted Ratio
14%
Uploaded By