I must combine values in a set in this way:
Input:
{A,B,C,D}
Result:
{AB, ABC, AC, AD, ACD, ABD, ABCD, BC, BD, BCD, CD}
How can I do this?
I must combine values in a set in this way:
Input:
{A,B,C,D}
Result:
{AB, ABC, AC, AD, ACD, ABD, ABCD, BC, BD, BCD, CD}
How can I do this?
Copyright © 2021 Jogjafile Inc.
There are several solutions depending upon the size of the input:
If the input-array is <= 64 and the input doesn't need to be sorted, we can represent each combination as a
long, where each bit is 1, if the corresponding element is in the produced output:If the output has to be sorted, we can easily solve this problem using a recursive solution: