Given a number N, the task is to minimize the number by changing at most K digits. Note that the number should not contain any leading zeros.
Input: N = 91945, K = 3
Input: N = 1, K = 0
- Replace the first digit with 1 if its not already 1 and update K accordingly.
- Now for the rest of the digits, replace the next K – 1 non-zero digits with a 0.
Below is the implementation of the above approach:
- Find the largest number that can be formed by changing at most K digits
- Minimize the sum of digits of A and B such that A + B = N
- Removing a number from array without changing its arithmetic mean
- Check if a number is power of k using base changing method
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Find smallest number with given number of digits and sum of digits under given constraints
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Minimize the cost to split a number
- Maximize the given number by replacing a segment of digits with the alternate digits given
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Find smallest number with given number of digits and sum of digits
- Find the Largest number with given number of digits and sum of digits
- Find the average of k digits from the beginning and l digits from the end of the given number
- Minimum number of digits to be removed so that no two consecutive digits are same
- Minimize the number of steps required to reach the end of the array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.