Given a number as a string, no leading zeros, determine the sum of all integer values of substrings of the string.
Given an integer as a string, sum all of its substrings cast as integers. As the number may become large, return the value modulo 10**9+7.
Full problem: https://www.hackerrank.com/challenges/sam-and-substrings
def substrings(n): ans=0 l=len(n) for i in range(l): ans+=int(n[i])*(i+1)*((10**(l-i)-1)//9) return ans%(10**9+7)
It's currently getting timed out otherwise passing all test cases. Even though the problem category is dynamic programming, I don't understand how it could be used, and I'm not sure what's slowing my code down.