Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Problem of the day

Given a number 'N', you need to find all possible unique ways to represent this number as the sum of positive integers.

```
1. By unique it is meant that no other composition can be expressed as a permutation of the generated composition. For eg. [1, 2, 1] and [1, 1, 2] are not unique.
2. You need to print all combinations in non-decreasing order for eg. [1, 2, 1] or [1, 1, 2] will be printed as [1, 1, 2], however, the order of printing all the sequences can be random.
```

Detailed explanation

```
The first and the only line of the input contains an integer 'N' representing the given number.
```

```
Each line of the output contains one unique sequence which sums up to 'N'.
There will be 'K' lines of output containing one unique sequence on each line in non-decreasing order which sums up to 'N'. 'K' is the total number of unique sequences.
```

```
You do not need to print anything, it has already been taken care of. Just implement the given function.
```

```
1 <= N <= 50
Time Limit: 1sec
```

```
4
```

```
4
1 1 1 1
1 1 2
2 2
1 3
```

```
Here notice that all combinations are sorted in non-decreasing order and [1, 1, 2] and [1, 2, 1] are the same and printed as [1, 1, 2].
Note: 1 1 1 1
2 2
4
1 3
1 1 2 is also a valid output as the order of different sequences doesn’t matter.
```

```
1
```

```
1
```