Advertisement
Josif_tepe

Untitled

Feb 6th, 2023
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. #define lli long long int
  5. #define li long int
  6. #define ld long double
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     int n;
  12.     cin >> n;
  13.     vector<int> arr(n);
  14.     for (int i = 0; i < n; i++)
  15.     {
  16.         cin >> arr[i];
  17.     }
  18.     int i = 0, j = 0, max_len = 0, curr_len = 0;
  19.     map<int, int> freq;
  20.     while (j < n)
  21.     {
  22.         if (freq[arr[j]] == 0)
  23.         {
  24.             freq[arr[j]]++;
  25.             curr_len++;
  26.             max_len = max(max_len, curr_len);
  27.             j++;
  28.         }
  29.         else
  30.         {
  31.             curr_len--;
  32.             freq[arr[i]]--;
  33.             i++;
  34.         }
  35.     }
  36.     cout << max_len;
  37.     return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement