Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <unordered_map>
- #include <unordered_set>
- using namespace std;
- int main() {
- string s;
- cin >> s;
- unordered_set<char> alf;
- for (auto el: s){
- alf.insert(el);
- }
- unordered_map<char, int> cur_alf;
- int l = 0;
- int r = 0;
- int ans = s.size();
- while (r != s.size()){
- while (r < s.size() && cur_alf.size() < alf.size()){
- ++cur_alf[s[r]];
- ++r;
- }
- while (cur_alf.size() == alf.size()){
- --cur_alf[s[l]];
- if (cur_alf[s[l]] == 0){
- cur_alf.erase(s[l]);
- }
- ++l;
- }
- ans = min(ans, r - l + 1);
- }
- cout << ans;
- }
- //abbac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement