Sam and substrings Discussions | Algorithms | HackerRank
  • + 28 comments
    I think I found a easier way than dp:
    long long int res = 0;
    long long int f = 1;
    for(int i = l-1; i >= 0; i--) {
        res = (res + (s[i]-'0')*f*(i+1)) % MOD;
        f = (f*10+1) % MOD;
    }