Math, asked by Manishdvarade8140, 10 months ago

Given an array of integers a and an integer b. Find and return all unique combinations in a where the sum of elements is equal to b.

Answers

Answered by Anonymous
23

 \large\boxed{\underline{\mathcal{\red{A}\green{n}\pink{s}\orange{w}\blue{e}\red{r:}}}}

Given an array of positive integers arr[] and a sum x, find all unique combinations in arr[] where the sum is equal to x. The same repeated number may be chosen from arr[] unlimited number of times. Elements in a combination (a1, a2, …, ak) must be printed in non-descending order. (ie, a1 <= a2 <= … <= ak).

The combinations themselves must be sorted in ascending order, i.e., the combination with smallest first element should be printed first. If there is no combination possible the print "Empty" (without quotes).

Examples:

Input : arr[] = 2, 4, 6, 8

x = 8

Output : [2, 2, 2, 2]

[2, 2, 4]

[2, 6]

[4, 4]

[8]

Answered by Anonymous
0

Answer:

Given an array of positive integers arr[] and a sum x, find all unique combinations in arr[] where the sum is equal to x. The same repeated number may be chosen from arr[] unlimited number of times. Elements in a combination (a1, a2, …, ak) must be printed in non-descending order. (ie, a1 <= a2 <= … <= ak).

The combinations themselves must be sorted in ascending order, i.e., the combination with smallest first element should be printed first. If there is no combination possible the print "Empty" (without quotes).

Examples:

Input : arr[] = 2, 4, 6, 8

x = 8

Output : [2, 2, 2, 2]

[2, 2, 4]

[2, 6]

[4, 4]

[8]

Similar questions