Sliding window
Sat Mar 23 2024 07:05:44 GMT+0000 (Coordinated Universal Time)
Saved by
@akshay@999
#sliding
int low=0;
int high=0;
queue<int>que;
vector<long long>V;
while(low<N && high<N)
{
if(A[high]<0)
{
que.push(A[high]);
}
if(high-low+1==k)
{
if(que.size()==0)
{
V.push_back(0);
}
else
{
V.push_back(que.front());
}
}
else if(high-low+1>k)
{
while(high-low+1>k)
{
if(A[low]==que.front())
{
que.pop();
}
low++;
}
if(high-low+1==k)
{
if(que.size()==0)
{
V.push_back(0);
}
else
{
V.push_back(que.front());
}
}
}
high++;
}
return V;
content_copyCOPY
First Negative Number in every Window of Size K | Sliding Window
https://www.geeksforgeeks.org/problems/first-negative-integer-in-every-window-of-size-k3345/1
Comments