Given a set of X items write an algorithm to obtain every combination of possible permutations to output unique subsets of 3 items. Order is irrelevant, {A B C} is the same as {B A C} Example: Input: {ABCD} Output: {ABC}, {ABD}, {ACD}, {BCD}
const sizeSubsets = function(input) {
size = input.length;
for(let i = 1; i < size-1; i++)
for(let j = i + 1; j < size-1; j++)
for(let k = j + 1; k < size-1; k++)
console.log("{"+input[i]+input[j]+input[k]+"}");
}
const input = "{ABCD}";
sizeSubsets(input);
the above standard solution gives required result but , I the time, space complexity costs high and if I am correct it it O(n).
Can it be better( alternative solution)?