Advertisement
Josif_tepe

Untitled

Dec 26th, 2021
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <map>
  4. using namespace std;
  5.  
  6.  
  7. int main()
  8. {
  9. int n;
  10. cin >> n;
  11. string s;
  12. cin >> s;
  13. map<char, int> mapa;
  14. int j = 0;
  15. int result = 2e9;
  16. for(int i = 0; i < n; i++) {
  17. mapa[s[i]]++;
  18. int k = mapa[s[i]];
  19. while(mapa[s[j]] > 1) {
  20. mapa[s[j]]--;
  21. j++;
  22. }
  23. if(k == 1) {
  24. result = i - j + 1;
  25. }
  26. else {
  27. result= min(result, i - j + 1);
  28. }
  29. }
  30. cout << result << endl;
  31. return 0;
  32. }
  33.  
  34. // 7
  35. //aaBCCee
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement