fork download
  1. //
  2. // Playlist
  3. //
  4. //
  5. // Created by Krish Narsaria on 05/01/25.
  6. //
  7.  
  8. #include <bits/stdc++.h>
  9. using namespace std;
  10. #define ll long long
  11. void solve() {
  12. unordered_map<int, int> lastIndex;
  13. int n, a, ans = 0, start = 0;
  14. cin >> n;
  15. for (int i = 0; i < n; i++) {
  16. cin >> a;
  17. if (lastIndex.find(a) != lastIndex.end() && lastIndex[a] >= start) {
  18. start = lastIndex[a] + 1;
  19. }
  20. lastIndex[a] = i;
  21. ans = max(ans, i - start + 1);
  22. }
  23. cout << ans << "\n";
  24. }
  25. int main(){solve();}
Success #stdin #stdout 0.01s 5284KB
stdin
8
1 2 1 3 2 7 4 2
stdout
5