Skip to content

Commit 17c7e0c

Browse files
authored
Merge pull request #13 from tannuchoudhary/patch-5
Create SamAndSubstring.cpp
2 parents 6a01d2e + 149f90a commit 17c7e0c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*Hackerrank problem "sam and substring"*/
2+
3+
int substrings(string n) {
4+
5+
long long total_sum = n[0]-'0';
6+
long long last_value = n[0] - '0';
7+
8+
for(int i=1; i<n.length(); i++){
9+
last_value = ((last_value*10)+((n[i]-'0')*(i+1)))%1000000007;
10+
total_sum = (total_sum + last_value)%1000000007;
11+
}
12+
return total_sum;
13+
}
14+
15+

0 commit comments

Comments
 (0)