SOPC009 Doubt

ques

https://www.codechef.com/SHPC2019/problems/SOPC009

my soln

/* YATIN KWATRA */

#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
using namespace std;

int main() {

int t;
cin >> t;
while(t--)
{
    int n,d;
    cin >> n >> d;
    map<string,bool>h;
    string s[n];
    int left[n];
    int  maxans = 0;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> s[i];
        if(i==0)
        {
            left[i] = 1;
            
        }
        else{
        
                    if(!h.count(s[i])) left[i] = left[i-1]+1;
                    else left[i] = left[i-1];
        }
        
        
        
        if(!h.count(s[i])) h[s[i]] = true;
        
        if(left[i] > maxans) maxans = left[i];
       // cout << left[i] << " ";
        
        
    }
   if(maxans > d) cout << d << endl;
   else cout << maxans << endl;
    
    
       
}
return 0;

}

what am i missing in this question ?

Although editorial is out
Consider this
1
6 3
A
B
B
C
C
D
Your code outputs 3 while actually the answer is 2.
The problem asks for maximum possible unique events over d consecutive days. Your code outputs maximum possible unique events over n days or d , whichever is smaller.
https://www.codechef.com/viewsolution/28394492
Read the problem carefully again.

my code outputs 2 for your input
can you please find any other input where it’ll fail

Outputs 3

idk whats happening with ideone :sweat_smile:
but u can check in codechef ide also it gives output as 2 only

BTW u can dry it
left array will have values like this
1 2 1 2 1 2
every time a repeated value is encountered , old hash table is cleared and left[i] becomes one and starts couting from
there and values are updated in the hash table

oh sry the code i posted was my earlier submission
my final code was a bit different.
And i understood the mistake u pointed out
thanks for respondng @bugs_bunny_001