Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- #include <unordered_map>
- using namespace std;
- int main() {
- unordered_map<int, int> map;
- int start = 0;
- int longest = 0;
- int n, a;
- cin >> n;
- for(int i = 0; i < n; i++){
- cin >> a;
- if(map.count(a) == 0 || map[a] < start){
- map[a] = i;
- continue;
- }
- if(i - start> longest)
- longest = i - start;
- start = map[a] + 1;
- map[a] = i;
- }
- if(n - start > longest)
- longest = n - start;
- cout << longest;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment