Skip to content

Commit

Permalink
Create 04.04.2024.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Masked-coder11 authored Apr 3, 2024
1 parent 5823951 commit eeca1c3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions 04.04.2024.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution
{
public:
//Function to find sum of all possible substrings of the given string.
long long sumSubstrings(string s){

// your code here
long long prev=0, curr=0, ans=0;
long long mod=1e9+7;

for(int i=0;i<s.length();i++){
curr=(s[i]-'0')*(i+1) + prev*10;
curr%=mod;
ans+=curr;
ans%=mod;
prev=curr;
}

return ans;
}
};

0 comments on commit eeca1c3

Please sign in to comment.