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 email@example.com. 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 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 in a string to make adjacent characters unequal
- Count of N-digit numbers having digit XOR as single digit
- 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
- Sum of square-sums of first n natural numbers
- Convert string X to an anagram of string Y with minimum replacements
- 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
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers