I am trying to solve the CSES Playlist problem.
https://cses.fi/problemset/task/1141/
I was thinking of a solution with using sets, as given in the code below.
It giving WA for 2 cases. But as this problem comes under Sorting and Searching, I have a feeling as there might be better solutions for this.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;int main() { ll n; cin >> n; set<ll> elm; ll ans = 0, length = 0; for (ll i = 0; i < n; i++) { int temp; cin >> temp; int size1 = elm.size(); elm.insert(temp); if (elm.size() > size1) { length = elm.size(); ans = max(ans, length); } else { elm.clear(); elm.insert(temp); } } cout << ans; return 0; }
Can someone please help out ?