Dp solution:
def sumSubstrings(self,s):
n = len(s)
dp = [0] * (n)
dp[0] = int(s[0])
res = int(s[0])
for i in range(1, n):
dp[i] = (i+1) * int(s[i]) + 10 * (dp[i-1])
res += dp[i]
return res % (10**9+7)
//User function Template for Java
class Solution
{
//Function to find sum of all possible substrings of the given string.
public static long sumSubstrings(String s)
{
long sum=0;
long mod=1000000007;
int count=s.length();
long one=1;
while(count>0)
{
long number=((s.charAt(count-1)-'0')*count)%mod;
long temp=(one*number)%mod;
//System.out.println(temp);
sum=(sum+temp)%mod;
one=(one*10+1)%mod;
count--;
}
return sum;
}
}
/*1111*count*number
222*2
33*3
4*count*/