Given a non-negative number N, the task is to convert the number by deleting some digits of the number, such that the sum of the digits becomes even but the number is odd. In case there is no possible number then print -1.
Note: There can be multiple numbers possible for a given N.
Input: N = 3
There is no possiblity such that number becomes odd and the digit-sum is even.
The idea is to use the fact that “Even number of odd digits will give the sum to even number”. So, If the digits in the number contain even count of odd digits then it is possible to convert the number otherwise converting such number is not possible.
Below is the implementation of the above approach.
- Find the Largest Cube formed by Deleting minimum Digits from a number
- Find maximum number that can be formed using digits of a given number
- Greatest number less than equal to B that can be formed from the digits of A
- Check if the number formed by the last digits of N numbers is divisible by 10 or not
- Find the largest number that can be formed by changing at most K digits
- Find Nth even length palindromic number formed using digits X and Y
- Recursive sum of digits of a number formed by repeated appends
- Find all strings formed from characters mapped to digits of a number
- 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
- 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 the Largest number with given number of digits and sum of digits
- Find smallest number with given number of digits and sum of digits
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.