Given a positive integer N, the task is to convert this integer to the minimum possible integer without leading zeroes by changing the digits. A digit X can only be changed into a digit Y if X + Y = 9.
Input: N = 589
Change 5 -> 4, 8 -> 1 and 9 -> 0
Input: N = 934
934 cannot be minimised.
Approach: Only the digits which are greater than or equal to 5 need to be changed as changing the digits which are less than 5 will result in a larger number. After all the required digits have been updated, check whether the resultant number has a leading zero, if yes then change it to a 9.
Below is the implementation of the above approach:
- Minimum number of given operation required to convert n to m
- Minimum possible sum of array elements after performing the given operation
- Maximum possible number with the given operation
- Generate number with given operation and check if it is palindrome
- Largest smaller number possible using only one swap operation
- Form the smallest number using at most one swap operation
- Next higher number using atmost one swap operation
- Form the largest number using at most one swap operation
- Check if the given array can be reduced to zeros with the given operation performed given number of times
- Find minimum number to be divided to make a number a perfect square
- Minimum number of given powers of 2 required to represent a number
- Convert a number m to n using minimum number of given operations
- Minimum number of squares whose sum equals to given number n
- Minimum number of bombs
- Add minimum number to an array so that the sum becomes even
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.