Given two positive numbers calculate the minimum and maximum possible sums of two numbers. We are allowed to replace digit 5 with digit 6 and vice versa in either or both the given numbers.
Input : x1 = 645 x2 = 666 Output : Minimum Sum: 1100 (545 + 555) Maximum Sum: 1312 (646 + 666) Input: x1 = 5466 x2 = 4555 Output: Minimum sum: 10010 Maximum Sum: 11132
Since both numbers are positive, we always get maximum sum if replace 5 with 6 in both numbers. And we get minimum sum if we replace 6 with 5 in both numbers. Below is C++ implementation based on this fact.
Minimum sum = 10010 Maximum sum = 11132
This article is contributed by Roshni Agarwal. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Minimum count of numbers required with unit digit X that sums up to N
- Count numbers whose maximum sum of distinct digit-sum is less than or equals M
- Minimum replacements such that the difference between the index of the same characters is divisible by 3
- Minimum number of replacements to make the binary string alternating | Set 2
- Minimum replacements to make adjacent characters unequal in a ternary string
- Minimum replacements to make adjacent characters unequal in a ternary string | Set-2
- Form lexicographically smallest string with minimum replacements having equal number of 0s, 1s and 2s
- Find Maximum and Minimum of two numbers using Absolute function
- Count of Numbers in Range where first digit is equal to last digit of the number
- Count numbers in a range with digit sum divisible by K having first and last digit different
- Queries on sum of odd number digit sums of all the factors of a number
- Convert string X to an anagram of string Y with minimum replacements
- Sum of square-sums of first n natural numbers
- Possible two sets from first N natural numbers difference of sums as D
- Count n digit numbers not having a particular digit
- Split N natural numbers into two sets having GCD of their sums greater than 1
- Sum of M maximum distinct digit sum from 1 to N that are factors of K
- Maximum sum of two elements whose digit sum is equal
- Find the minimum number possible by changing at most one digit
- Find minimum possible digit sum after adding a number d