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 possibility 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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Count of characters in str1 such that after deleting anyone of them str1 becomes str2
- Count numbers from given range having odd digits at odd places and even digits at even places
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
- Find the Largest Cube formed by Deleting minimum Digits from a number
- Check if a number has an odd count of odd divisors and even count of even divisors
- Finding sum of digits of a number until sum becomes single digit
- Add minimum number to an array so that the sum becomes even
- Count total number of N digit numbers such that the difference between sum of even and odd digits is 1
- Find third number such that sum of all three number becomes prime
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Number of positions where a letter can be inserted such that a string becomes palindrome
- Find Nth even length palindromic number formed using digits X and Y
- Find the sum of digits of a number at even and odd places
- Minimum value to be assigned to the elements so that sum becomes greater than initial sum
- Remove characters from a numeric string such that string becomes divisible by 8
- Remove minimum elements from the array such that 2*min becomes more than max
- Smallest odd number with even sum of digits from the given number N
- Delete odd and even numbers at alternate step such that sum of remaining elements is minimized
- Print all n-digit numbers with absolute difference between sum of even and odd digits is 1
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.