You are initializing char array ‘str’ of size 10 and taking input of length more than than. Thatswhy you are getting the error.
Initialize ‘str’ of size 10^6. As mentioned in problem constraints.
Btw your solution is not efficient.
It is a simple observation, for a string with length more than 10, the answer will be zero bcz there are only 10 distinct digits(0,1,2,3,4, . . . ,8,9). So string with length more than 10 will contain repeated digits. And absolute difference between them will be 0 that will make your answer 0.
So, you have to calculate only for (length <=10).
Here is solution. click here