#GD0000207. Xóa K chữ số (Remove K Digits)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Xóa K chữ số (Remove K Digits)
Remove K Digits
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
A decimal string num represents a non-negative integer. You must remove exactly digit positions, keeping the relative order of the remaining digits.
Interpret the remaining string as a decimal integer. Leading zeros have no effect on its value and must be removed from the output. If all digits are deleted or all remaining digits are zero, return 0.
Find the smallest possible integer. This is the standard-input/stdout adaptation of the original LeetCode function task.
Input
- The first line contains a decimal string
num, the initial integer representation. - The second line contains an integer , the exact number of digit positions to remove.
Let .
Output
Print the standard decimal representation, without leading zeros, of the smallest integer obtainable after removing exactly digits. Print exactly 0 if its value is zero.
Subtasks
- Subtask 1 (20 points): ;
numconsists of digits0–9; its first digit is nonzero except whennumis0. - Subtask 2 (30 points): ;
numconsists of digits0–9; its first digit is nonzero except whennumis0. - Subtask 3 (50 points): ;
numconsists of digits0–9; its first digit is nonzero except whennumis0.
Examples
Input
1432219
3
Output
1219
Explanation
For 1432219 and , remove digits 4, 3, and one appropriate 2 while preserving the order of the remaining digits. The resulting sequence is 1219. When scanning the number, each newly encountered smaller digit causes a larger previous digit to be deleted while deletions remain; these three deletions yield the minimum 1219.