All Possible Combinations for a Given Sum

Given a positive integer as target, print all the possible combinations of positive integers that sum to the target number.

Statement

Given a positive integer as the target, print all the possible combinations of positive integers that sum to the target number.

Example

Sample input

4

Expected output

[[1, 1, 1, 1], [1, 1, 2], [1, 3], [2, 2]]

Try it yourself

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.