Header Ad

HackerEarth Good String problem solution

In this HackerEarth Good String problem solution we have given a string S, print the minimum number of characters you have to remove from the string S to make it a good string. A good string is a string in which all the characters are distinct.


HackerEarth Good String problem solution


HackerEarth Good String problem solution.

#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define be begin()
#define en end()
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define REP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define REPI(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define REPITER(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds

#define eps 1e-6
#define pi 3.141592653589793

using namespace std;

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y); }
template<class T> inline T mod(T x) { if(x < 0) return -x; else return x; }

typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;

const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX = 30;
bool A[MAX];

int main(int argc, char* argv[])
{
if(argc == 2 or argc == 3) freopen(argv[1], "r", stdin);
if(argc == 3) freopen(argv[2], "w", stdout);
ios::sync_with_stdio(false);
string s;
int ans = 0;
cin >> s;
REP(i, 0, s.length(), 1)
{
if(A[s[i] - 'a']) ans++;
else A[s[i] - 'a'] = true;
}
cout << ans << endl;
return 0;
}

Second solution

S = raw_input()
print len(S) - len(set(S))

Post a Comment

0 Comments