Given an integer N ≥ 1, the task is to find the smallest and the largest sum of two N digit numbers.
Input: N = 1
Largest = 18
Smallest = 0
Largest 1-digit number is 9 and 9 + 9 = 18
Smallest 1-digit number is 0 and 0 + 0 = 0
Input: N = 2
Largest = 198
Smallest = 20
- For largest: The answer will be 2 * (10N – 1) because the series of sum of two n digit numbers will go on like 2 * 9, 2 * 99, 2 * 999, …
- For smallest:
- If N = 1 then the answer will be 0.
- If N > 1 then the answer will be 2 * (10N – 1) because the series of sum of two n digit numbers will go on like 0, 20, 200, 2000, …
Below is the implementation of the above approach:
Largest = 19998 Smallest = 2000
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Largest and Smallest N-digit Octal Numbers
- Largest and Smallest N-digit Hexadecimal Numbers
- Sum and product of k smallest and k largest composite numbers in the array
- Sum and product of k smallest and k largest prime numbers in the array
- Largest and smallest digit of a number
- Smallest and Largest Palindrome with N Digits
- Smallest and Largest N-digit perfect squares
- Smallest and Largest N-digit perfect cubes
- Queries for the smallest and the largest prime number of given digit
- Split the number into N parts such that difference between the smallest and the largest part is minimum
- Smallest number divisible by first n numbers
- Largest Even and Odd N-digit numbers
- Smallest n digit number divisible by given three numbers
- Count all the numbers in a range with smallest factor as K
- Arrange given numbers to form the smallest 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 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.