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.
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.
- Minimum count of numbers required with unit digit X that sums up to N
- Minimize difference between maximum and minimum of Array by at most K replacements
- Count of N-digit numbers having digit XOR as single digit
- Split first N natural numbers into two sets with minimum absolute difference of their sums
- Split squares of first N natural numbers into two sets with minimum absolute difference of their sums
- Form lexicographically smallest string with minimum replacements having equal number of 0s, 1s and 2s
- Convert string X to an anagram of string Y with minimum replacements
- Minimum replacements to make adjacent characters unequal in a ternary string
- Minimum replacements such that the difference between the index of the same characters is divisible by 3
- Minimum replacements to make adjacent characters unequal in a ternary string | Set-2
- Minimum number of replacements to make the binary string alternating | Set 2
- Minimum replacements in a string to make adjacent characters unequal
- Convert given string to another by minimum replacements of subsequences by its smallest character
- Minimum replacements required to obtain a K-periodic palindromic string
- Count minimum character replacements required such that given string satisfies the given conditions
- Minimize replacements or swapping of same indexed characters required to make two given strings palindromic
- Queries on sum of odd number digit sums of all the factors of a number
- Partition a set into two non-empty subsets such that the difference of subset sums is maximum
- Possible two sets from first N natural numbers difference of sums as D
- Split N natural numbers into two sets having GCD of their sums greater than 1