Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <map>
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- string s;
- cin >> s;
- map<char, int> mapa;
- int j = 0;
- int result = 2e9;
- for(int i = 0; i < n; i++) {
- mapa[s[i]]++;
- int k = mapa[s[i]];
- while(mapa[s[j]] > 1) {
- mapa[s[j]]--;
- j++;
- }
- if(k == 1) {
- result = i - j + 1;
- }
- else {
- result= min(result, i - j + 1);
- }
- }
- cout << result << endl;
- return 0;
- }
- // 7
- //aaBCCee
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement