vector<string> result;
// storing the concatenation of digits as a string as it is to operate on, we can convert the concatenated string to int at the end.
FormDigits(vector<int> input, int index, int n, string ndigits) {
// if the ndigits size has reached n
// Check whether that is already present in the result as we have repeating digits
if(ndigits.size() == n && result.find(ndigits) != result.end()) {
result.push(ndigits);
}
// if ndigits size hasnt yet reached run a loop and add next digit
else {
for(int i=index; i<input.size(); i++) {
FormDigits(input,i,n,digit+to_string(arr[i]));
}
}
}
Вышеуказанная функция должна вызываться из main как
FormDigits(InputArray, 0, n, "");
Вектор результата - это конечный результат.