{"id":"4c8d3d48-2e71-439b-9f91-4526db29c3c5","name":"Remove K Digits","description":"Given string num representing a non-negative integer num, and an integer k, print the smallest possible integer after removing k digits from num.\r\n","inputFormat":"A string num\r\nA number k","outputFormat":"A string representing smallest possible integer after removing k digits from num. Output should not contain any leading 0 except for the 0 itself.\r\n","constraints":"1: 1 &lt;= k &lt;= num.length &lt;= 10^5\r\n2: num consists of only digits.\r\n3: num does not have any leading zeros except for the zero itself.","sampleCode":{"cpp":{"code":"#include<iostream>\n#include<vector>\n#include<stack>\n\nusing namespace std;\n\nint main(){\n string num;\n cin >> num;\n int k;\n cin >> k;\n // write your code here\n \n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n String num = read.readLine();\r\n int k = Integer.parseInt(read.readLine());\r\n\r\n // write your code here\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"1432219\r\n3","sampleOutput":"1219\r\n","questionVideo":"https://www.youtube.com/embed/RCE2L0Zk7xE","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"0026b453-8a54-43bb-ab30-a523aec78938","name":"Remove K Digits","slug":"remove-k-digits","type":1}],"next":{"id":"6e1030f8-e468-4fe8-926e-be7ec0fb8562","name":"Remove K Digits Medium MCQ","type":0,"slug":"remove-k-digits-medium-mcq"},"prev":{"id":"584450b4-8adc-455d-9c59-98f285da632f","name":"Asteroid Collision","type":3,"slug":"asteroid-collision"}}}

Remove K Digits

Given string num representing a non-negative integer num, and an integer k, print the smallest possible integer after removing k digits from num.

{"id":"4c8d3d48-2e71-439b-9f91-4526db29c3c5","name":"Remove K Digits","description":"Given string num representing a non-negative integer num, and an integer k, print the smallest possible integer after removing k digits from num.\r\n","inputFormat":"A string num\r\nA number k","outputFormat":"A string representing smallest possible integer after removing k digits from num. Output should not contain any leading 0 except for the 0 itself.\r\n","constraints":"1: 1 &lt;= k &lt;= num.length &lt;= 10^5\r\n2: num consists of only digits.\r\n3: num does not have any leading zeros except for the zero itself.","sampleCode":{"cpp":{"code":"#include<iostream>\n#include<vector>\n#include<stack>\n\nusing namespace std;\n\nint main(){\n string num;\n cin >> num;\n int k;\n cin >> k;\n // write your code here\n \n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n String num = read.readLine();\r\n int k = Integer.parseInt(read.readLine());\r\n\r\n // write your code here\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"1432219\r\n3","sampleOutput":"1219\r\n","questionVideo":"https://www.youtube.com/embed/RCE2L0Zk7xE","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"0026b453-8a54-43bb-ab30-a523aec78938","name":"Remove K Digits","slug":"remove-k-digits","type":1}],"next":{"id":"6e1030f8-e468-4fe8-926e-be7ec0fb8562","name":"Remove K Digits Medium MCQ","type":0,"slug":"remove-k-digits-medium-mcq"},"prev":{"id":"584450b4-8adc-455d-9c59-98f285da632f","name":"Asteroid Collision","type":3,"slug":"asteroid-collision"}}}
plane

Editor


Loading...

Remove K Digits

medium

Given string num representing a non-negative integer num, and an integer k, print the smallest possible integer after removing k digits from num.

Constraints

1: 1 <= k <= num.length <= 10^5 2: num consists of only digits. 3: num does not have any leading zeros except for the zero itself.

Format

Input

A string num A number k

Output

A string representing smallest possible integer after removing k digits from num. Output should not contain any leading 0 except for the 0 itself.

Example

Sample Input

1432219 3

Sample Output

1219

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode