Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Sum of all substrings of a number

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)
Source by practice.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #Sum #substrings #number
ADD COMMENT
Topic
Name
8+8 =