Birthday Candles

#include
#include

using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int DATA[10];
        bool st =0;
        int minimalC = 999999999;
        int minimalIndex = -1;
        for(int i = 0;i<10;i++){
            cin>>DATA[i];
            if(i > 0){
                if(DATA[i]==0){
                    cout<<i<<endl;
                    st = 1;
                }
                if(DATA[i] < minimalC){
                    minimalC = DATA[i];
                    minimalIndex = i;
                }
            }
        }
        if(!st){
            int minten = pow(10,DATA[0]+1);
            int minval = 0;
            int i = 0;
            DATA[minimalIndex]++;
            while(DATA[minimalIndex] > 0){
                minval += pow(10,i) * minimalIndex;
                i++;
                DATA[minimalIndex]--;
            }
            int result = minten > minval ? minval : minten;
            cout<<result<<endl;
        }
    }
    return 0;
}

Why is this solution incorrect? Please provide me a test case where this algorithm breaks.
What my solution does is it first checks whether any of the integers between 1 and 9 are 0 and if they are then it outputs the answer otherwise it checks which is the smallest integer between the set DATA[1…9] and I form the needed integer since it will have the lowest count of characters in the integer representation and just get the min with the integer that forms from DATA[0].

Please help!

OK I FOUND MY ERROR :slight_smile: I wasn’t expecting a 0 0 0 0 0 0 0 0 0 0 input . I feel so happy ! :smiley:

Your code fails if the input is
0 0 0 0 0 0 0 0 0 0
You are printing all the values while you need to print only 1.

SORRY. I didn’t see that you found your error. So I posted the answer. Good work.