Print unique subarrays with expected sum.
input: a ={1,1,2,5,6,7} and expectedSum=8
expected output:
[1, 1, 6]
[1, 2, 5]
[1, 7]
[2, 6]I did the standard backtracking of calculating the sum and print. But it printed out duplicates of [1,2,5] and [1,7] as there are two 1s. For the uniqueness, I proposed having a Set of arrays probably. But he was looking for other options.
How can we improve the backtracking to print unique array?