Created
August 28, 2021 07:45
-
-
Save hinupurthakur/bdecd7f75bc3f5d40bb82e8bee7cea5e to your computer and use it in GitHub Desktop.
Modulo Concept: https://www.geeksforgeeks.org/modulo-1097-1000000007/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
long long solve (string S) { | |
// Write your code here | |
long long mod=1000000007; //10^9+7 to prevent integer overflow | |
S = " "+S; | |
int freq[30]={0}; | |
for(int i=1;i<S.size();i++){ | |
freq[S[i]-'a']++; | |
} | |
long long ans=1; | |
for(int i=0;i<26;i++){ | |
if(freq[i]){ | |
ans*=freq[i]; | |
ans%=mod; | |
} | |
} | |
return ans; | |
} | |
int main() { | |
ios::sync_with_stdio(0); | |
cin.tie(0); | |
int T; | |
cin >> T; | |
for(int t_i=0; t_i<T; t_i++) | |
{ | |
string S; | |
cin>>S; | |
long long out_; | |
out_ = solve(S); | |
cout << out_; | |
cout << "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment