Help me out in this


@KartikKhariwal are u there ?

yeah… having some internet issues just hold on :slight_smile:

Hey @shivammishra20121999
Please explain this

    for(int i=1;i<=k;i++)
    {
        n=n+n;
    }

Also u cant use atoi , see the constraints ,

@Kartikkhariwal1 okay i got it

1 Like

Here also updted ur code

int calculate (long long int num) //updated long long
{
    if(num>=0 && num<=9)
    {
        return num;
    }
    int sum=0;
    int rem;
    while(num>0)
    {
        rem=num%10;
        sum+=rem;//upated this because digit sum
        num=num/10;
    }
    return calculate(sum);//updated this sending sum
}
int superDigit(string n, int k) {
    long long int num=0;//added this
    for(int i=1;i<=n.length();i++) //updated n.lenght()
    {
        num+=n[i-1]-'0';//updated this: adding digits
    }
    num*=k; //added : k times concat
    // int num=stoi(n);removed this
    // cout<<num;
    int res=calculate(num);
    return res;
}

@Kartikkhariwal1 it is still giving error have you submitted on hackerrankj??/

Yes I did @shivammishra20121999

Can u please share ur code again,I will check

@Kartikkhariwal1 ho gaya bro

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.