Advertisement
jakaria_hossain

Codeforce - They are everywhere

Oct 21st, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define pb push_back
  4. map<char,int>mp;
  5. int ans=100002;
  6. int main()
  7. {
  8. int n;
  9. scanf("%d",&n);
  10. cin.ignore();
  11. string s;
  12. getline(cin,s);
  13. list<int>ls;
  14. for(int i=0;i<n;i++)
  15. {
  16. int temp=s[i];
  17. ls.pb(temp);
  18. }
  19. ls.sort();
  20. ls.unique();
  21. int i=0,cnt=0,left=0,counter=ls.size();
  22. while(i<n)
  23. {
  24. if(!mp[s[i]])cnt++;
  25. mp[s[i]]++;
  26. while(mp[s[left]]>1)
  27. {
  28. mp[s[left]]--;
  29. left++;
  30. }
  31. if(cnt==counter)ans=min(ans,i-left+1);
  32. i++;
  33. }
  34. printf("%d\n",ans);
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement