Given an integer N, the task is to find the greatest number less than N such that the sum of its digits is greater than the sum of the digits of N. If the condition isn’t satisfied for any number then print -1.
Input: N = 100
99 is the largest number less than 100 sum of whose digits is greater than the sum of the digits of 100
Input: N = 49
Approach: Start a loop from N-1 to 1 and check whether the sum of the digits of any number is greater than the sum of the digits of N. The first number that satisfies the condition is the required number.
Below is the implementation of the above approach:
- Largest even digit number not greater than N
- Least Greater number with same digit sum
- Largest and smallest digit of a number
- Largest K digit number divisible by X
- Count of Numbers in Range where first digit is equal to last digit of the number
- Count numbers with difference between number and its digit sum greater than specific value
- C++ Program for Largest K digit number divisible by X
- Largest N digit number divisible by given three numbers
- Find the remainder when First digit of a number is divided by its Last digit
- Largest Even and Odd N-digit numbers in Octal Number System
- Largest N digit Octal number which is a Perfect square
- Largest Even and Odd N-digit numbers in Hexadecimal Number System
- Java Program for Largest K digit number divisible by X
- Queries for the smallest and the largest prime number of given digit
- Largest number less than N whose each digit is prime number
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.