![]() |
VOOZH | about |
Given a fraction N/D, the task is to split this fraction into N parts such that their sum is equal to the fraction N/D, i.e.,
Note: Represents the terms in terms of fractions, instead of floating point numbers.
Input: N = 4, D = 2
Output: 4/5, 1/5, 1/3, 4/6
Explanation:
Therefore, it is a valid set of fractions such that their sum is
Input: N = 3, D = 4
Output: 1/2, 1/10, 3/20
Explanation:
Therefore, it is a valid set of fractions such that their sum is
Approach: The key observation in the problem is that the first fraction numerator can be and then further denominators can be using the below recurrence relation.
Below is the implementation of the above approach:
4/5, 1/5, 1/3, 4/6,
Time Complexity: O(n), where n is the given integer.
Auxiliary Space: O(n), where n is the given integer.