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.
- 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
- Form lexicographically smallest string with minimum replacements having equal number of 0s, 1s and 2s
- Minimum replacements to make adjacent characters unequal in a ternary string
- Minimum replacements to make adjacent characters unequal in a ternary string | Set-2
- Count of Numbers in Range where first digit is equal to last digit of the number
- 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
- Count n digit numbers not having a particular digit
- Sum of square-sums of first n natural numbers
- Possible two sets from first N natural numbers difference of sums as D
- Maximum sum of two elements whose digit sum is equal
- Find minimum possible digit sum after adding a number d
- Biggest integer which has maximum digit sum in range from 1 to n
- Maximum number with same digit factorial product