Why I'm getting 8 at last index of output

question link=>

class Solution {

public List<Integer> addToArrayForm(int[] num, int k) {
    List<Integer> ans= new ArrayList<>();
    long n=0;
    for(int i:num){
        n = (n*10)+i;
    }
    n+=k;
    while(n>0){
        ans.add(0,(int)n%10);
        n/=10;
    }
    return ans;
}

}

Input
[9,9,9,9,9,9,9,9,9,9]
1

Output
[1,0,0,0,0,0,0,0,0,0,8]

Expected
[1,0,0,0,0,0,0,0,0,0,0]

@nayankamalverma_51f44fd6fd2fd365 Since You have to treat whole array as a number that means a number can be very very large which cannot be stored even in long . So you have to change your logic in which you have to add the numbers directly to array not by storing in a long or int and then Adding this will not be accepted.

1 Like

Thanks ,got it… :metal:

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.