aboutsummaryrefslogtreecommitdiff
path: root/02_sorting_and_searching/playlist_1141.cpp
blob: ff963f7bbffea52a63bc5b822ddc611be9a5916d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

int main() {
	size_t n;
	std::cin >> n;
	std::vector<int> v(n);
	for (size_t i = 0; i < n; i++)
		std::cin >> v[i];

	size_t l{0}, s{0};
	std::map<int, size_t> m;
	for (size_t r = 0; r < n; r++) {
		if (m.contains(v[r]))
			l = std::max(l, m.at(v[r])+1);
		m[v[r]] = r;
		s = std::max(s, r-l+1);
	}
	std::cout << s << "\n";
}

Generated with cgit - Back to sebastiano.tronto.net