Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- #define lli long long int
- #define li long int
- #define ld long double
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- vector<int> arr(n);
- for (int i = 0; i < n; i++)
- {
- cin >> arr[i];
- }
- int i = 0, j = 0, max_len = 0, curr_len = 0;
- map<int, int> freq;
- while (j < n)
- {
- if (freq[arr[j]] == 0)
- {
- freq[arr[j]]++;
- curr_len++;
- max_len = max(max_len, curr_len);
- j++;
- }
- else
- {
- curr_len--;
- freq[arr[i]]--;
- i++;
- }
- }
- cout << max_len;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement