Problem 26: Remove K digits to create smallest number[Microsoft]
String Manipulation, Integer Typecasting, Greedy Approach
Problem
This problem was asked by Microsoft.
Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible.
Example 1
Input: num = "1432219", k = 3
Output: "1219"
Explanation: Remove the three digits 4, 3, and 2 to form the new number 1219 which is the smallest.
Example 2
Input: num = "10200", k = 1
Output: "200"
Explanation: Remove the leading 1 and the number is 200. Note that the output must not contain leading zeroes.
Example 3
Input: num = "10", k = 2
Output: "0"
Explanation: Remove all the digits from the number and it is left with nothing which is 0.
Make sure you like this question on Substack. It really helps the newsletter grow. The solution to this problem will be shared tomorrow with the premium subscribers of the newsletter.
Consider filling out this survey. This helps me understand you better and will allow me to improve the content: Link: https://forms.gle/XfTXSjnC8W2wR9qT9
If you’re serious about getting good at coding/Leetcode interviews, consider getting a premium subscription. It will let you get high-paying jobs at prestigious firms for less than 50 cents (30 Rupees) per day (only INR 800/month or roughly 10 USD/month).
Proven benefits include:
Learn about the concepts and knowledge needed to solve various interview questions.
Handpicked questions/solutions from me to maximize your interview prep.
Learn how to read and analyze the question the correct way to identify the correct data structures, algorithms, and optimizations.
Plenty of interview-related tips and tricks to stand out in your interviews.
All Patron Benefits (code reviews, annotated papers, and Machine Learning Consultations)
Learn from a global community, acing their interviews worldwide.
Check out a sample solution here. You can expect such high-quality solutions every week when you subscribe. Don’t miss an opportunity to supercharge your learning.
Was this question easy for you? Hard? Seen it somewhere before? Let me know in the comments below
Bonuses/Promotion (Get Free Stuff)
For most of my students, mock interviews have been very helpful. Enough mock interview practice is the key between getting that job offer and rejection. If you can get three people to become paying subscribers to this newsletter, you win a free mock interview. This offer has no upper limit, so the more subs you can get, the more mock interviews you win.
For one-time support of this newsletter. Any amount is appreciated and helps a lot. Supporting allows for exclusive benefits like annotated research papers, bonus discussions, and discounted rates for calls:
Venmo: https://account.venmo.com/u/FNU-Devansh
Paypal: paypal.me/ISeeThings
To share interesting problems/solutions with me, reach out to me. Different social media of mine also have other content from me. Good problems and/or solutions receive a free shoutout + 2 months of the paid newsletter:
Reach out to me on:
Instagram: https://www.instagram.com/iseethings404/
Message me on Twitter: https://twitter.com/Machine01776819
My LinkedIn: https://www.linkedin.com/in/devansh-devansh-516004168/
My content:
Read my articles: https://rb.gy/zn1aiu
My YouTube: https://rb.gy/88iwdd
Get a free stock on Robinhood. No risk to you, so not using the link is losing free money: https://join.robinhood.com/fnud75
What an interesting question. Thanks for sharing