Given an integer N containing the digit 4 at least once. The task is to divide the number into two parts x1 and x2 such that:
- x1 + x2 = N.
- And none of the parts contain the digit 4.
Note that there may be multiple answers.
Input: N = 4
Output: 1 3
1 + 3 = 4
Input: N = 9441
Output: 9331 110
9331 + 110 = 9441
Approach: Since number can be too large take the number as string. Divide it into two strings:
- For string 1, find all the positions of digit 4 in the string change it to 3 we can also change it to another number.
- For the second string put 1 at all positions of digit 4 and put 0 at all remaining positions from the 1st position of digit 4 to the end of the string.
Below is the implementation of the above approach:
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.
- Divide a big number into two parts that differ by k
- Divide number into two parts divisible by given numbers
- Divide a number into two parts such that sum of digits is maximum
- Count number of ways to divide a number in 4 parts
- Find the number of ways to divide number into four parts such that a = c and b = d
- Divide N into K unique parts such that gcd of those parts is maximum
- Divide N into K parts in the form (X, 2X, ... , KX) for some value of X
- Divide a string in N equal parts
- Divide an isosceles triangle in two parts with ratio of areas as n:m
- Minimum cuts required to divide the Circle into equal parts
- Count ways to divide C in two parts and add to A and B to make A strictly greater than B
- Divide a sorted array in K parts with sum of difference of max and min minimized in each part
- Split a number into 3 parts such that none of the parts is divisible by 3
- Split a string in equal parts such that all parts are palindromes
- Partition the string in two parts such that both parts have at least k different characters
- Break the number into three parts
- Partition a number into two divisible parts
- Sum of all second largest divisors after splitting a number into one or more parts
- Possible cuts of a number such that maximum parts are divisible by 3
- Find count of digits in a number that divide the 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 firstname.lastname@example.org. 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.