pls help me to optimise this code.The last tc is giving tle.
Optimisation of the code
hello @Senjuti256
cin and cout are generally slow use fast io to make ur program bit fast.
ios_base::sync_with_stdio(false);
cin.tie(NULL);
add these two lines in ur code , just after int main.
read more about fast io from here-> link
I found that on removing the the equality in the while loop of line 36 the tc 7 is getting passed.But why is this happening??
it just pop less element from ur deque ( becuase it will not pop elements that are equal ) hence takes less time.
Thanks a lot. So this is also a kind of optimization but if we don’t remove the repeating elements from queue how will the upcoming elements fit in the queue since the queue has a fixed size.
it will remove only when it is required.
while(!q.empty() && q.front()<=i-k)
{
q.pop_front();
}
these lines are used to remove stale entries(entries that are not part of current window).
dry run the code for clarity.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.