My issue
help
My code
#include<bits/stdc++.h>
#define int long long int
using namespace std;
const int N=1e5+10;
int dp[N];
void solve(){
string s;
cin>>s;
int n=(int)s.size();
map<char,int> mp;
for(auto &it:s){
mp[it]++;
}
int ans=INT_MAX;
for(char ch='a' ; ch<='z' ; ch++){
int c=0;
if(mp[ch]==0) continue;
for(int i=0 ; i<n ; i++){
if(s[i]==ch){
c++;
if(i==n-1) ans=min(mp[ch]-c,ans);
}else{
ans=min(mp[ch]-c,ans);
c=0;
}
}
}
cout<<ans<<"\n";
}
int32_t main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t=1;
std::cin >> t;
for(int i=0 ; i<t ; i++){
solve();
}
return 0;
}
/*
If debugging is the process of removing software bugs,
then programming must be the process of putting them in.
- Edsger Dijkstra
*/
Problem Link: Swap and Unite Practice Coding Problem - CodeChef