Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description Ramesh is given an integer n and a string num. He has to create the smallest number possible by removing n digits from

image

Description Ramesh is given an integer n and a string num. He has to create the smallest number possible by removing n digits from num (the removed digits may or may not be contiguous). The value returned must also be a string. For example. If Ramesh has num = "1432219" and n = 3, then we must remove the digits 4, 3, and 2 to get the smallest value i.e. "1219", It should be noted that if after removing n digits, the num is empty, you must return "0". In addition, all leading zeros must be removed before returning the string. Can you help Ramesh find a solution to this problem? Input Format - The first line in input is n and the second line contains a string. Output Format - Output is a string with the smallest possible value. Constraints The first line inputs an integer n and the second line inputs a string num. The length of num is denoted by len. 0

Step by Step Solution

3.46 Rating (149 Votes )

There are 3 Steps involved in it

Step: 1

include include include stdstring removeDigitsint n const stdstring num stdstack stack int toRemove ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming Language Pragmatics

Authors: Michael L. Scott

4th Edition

0124104096, 978-0124104099

More Books

Students also viewed these Programming questions

Question

Why do we require that w i i = 0 for all 1 i n?

Answered: 1 week ago