Smallest quantity higher than Okay by eradicating digits from N

[ad_1]

  

#embody <bits/stdc++.h>

utilizing namespace std;

int ans = 0;

  

void discover(int i, vector<int>& digits, int masks, int okay)

{

    

    if (i == digits.measurement())

        return;

  

    

    int temp = 0;

    int pow_of_10 = 1;

    for (int j = digits.measurement() - 1; j >= 0; j--) {

        int okay = pow(2, j);

  

        

        

        if (!(masks & okay)) {

            temp = temp + pow_of_10 * digits[j];

            pow_of_10 *= 10;

        }

    }

    if (temp > okay) {

        ans = min(ans, temp);

    }

    int subsequent = pow(2, i);

    discover(i + 1, digits, masks, okay);

    discover(i + 1, digits, masks | subsequent, okay);

}

  

int GreaterthanK(int N, int Okay)

{

    

    vector<int> digits;

    int M = N;

    whereas (M) {

        digits.push_back(M % 10);

        M /= 10;

    }

    reverse(digits.start(), digits.finish());

    ans = N;

    discover(0, digits, 0, Okay);

    return ans;

}

  

int major()

{

    int N = 121230;

    int Okay = 756;

  

    

    cout << (GreaterthanK(N, Okay)) << endl;

    return 0;

}

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *