Combinations Problem IV
Given an integer array, find all distinct combinations of a given length `k`, where the repetition of elements is allowed.
Input : [1, 2, 3], k = 2
Output: {[1, 1], [1, 2], [1, 3], [2, 2], [2, 3], [3, 3]}Input : [1, 1, 1], k = 2
Output: {[1, 1]}Input : [1, 2], k = 0
Output: {[]}Input : [], k = 1
Output: {}
The solution should consider only distinct combinations. For example, either [1, 1, 2] or [1, 2, 1] or [2, 1, 1] should be considered for the below input. Same goes for [1, 2, 2] or [2, 1, 2] or [2, 2, 1].
Input : [1, 2, 1], k = 3
Output: {[1, 1, 1], [1, 1, 2], [1, 2, 2], [2, 2, 2]}
Practice link: https://www.techiedelight.com/?problem=CombinationsIV