Sam and substrings Discussions | Algorithms | HackerRank
  • + 0 comments
    long substrings(string s) {
        long total = 0, endRight = 0, mod = 1000000007;
        for (int i=0; i < s.size(); i++) {
            int k = s[i] - '0';
            endRight = (10*endRight + (i+1)*k) % mod;
            total = (total + endRight) % mod;
        }
        return total;
    }