You are given an array of distinct positive integers and a target value target. Your task is to find all unique combinations of elements whose sum equals the target.
You may use the same element multiple times. Return all valid combinations. The order of elements inside a combination does not matter.
Example 1
Input: arr[] = [2], target = 4
Output: [2 2]
Explanation: The element 2 can be used twice to reach the target.
Example 2
Input: arr[] = [2 3 6 7], target = 7
Output: [2 2 3] [7]
Explanation: Different combinations of the numbers add up to 7.
Example 3
Input: arr[] = [2 3 5], target = 8
Output: [2 2 2 2] [2 3 3] [3 5]
Explanation: Multiple selections of the given numbers form different sums equal to 8.
Sign in to write, run, and submit your solution against the full test suite.