[Solved] Forming the smallest number [closed]


As others have pointed out sorting and removing duplicates is possible. But how about this algorithm (in pseudocode, implementation is left to the reader)?

bool contains(int x, int digit); // returns true if x contains digit in base 10 notation

int res = 0;
for (int digit = 0; digit <= 9; ++i) {
    if (contains(intput, digit)) res = 10 * res + digit;
}
return res;

1

solved Forming the smallest number [closed]