Wrong Answer in TC


#1

Getting wa in the following test case.
A : [ 648, 614, 490, 138, 657, 544, 745, 582, 738, 229, 775, 665, 876, 448, 4, 81, 807, 578, 712, 951, 867, 328, 308, 440, 542, 178, 637, 446, 882, 760, 354, 523, 935, 277, 158, 698, 536, 165, 892, 327, 574, 516, 36, 705, 900, 482, 558, 937, 207, 368 ]
B : 9

vector Solution::slidingMaximum(const vector &A, int B) {

vector<int> ans;
deque<int> dq;
for(int j = 0;j<B;j++)
{
    dq.push_front(j);
    while(dq.front()!=dq.back() && A[dq.front()]>=A[dq.back()])
    {
        dq.pop_back();
    }
}


ans.push_back(A[dq.back()]);

for(int j = B;j<A.size();j++)
{
    dq.push_front(j);
    if(dq.back()==j-B)
    {
        dq.pop_back();
    }
    while(dq.front()!=dq.back() && A[dq.front()]>=A[dq.back()])
    {
        dq.pop_back();
    }
    ans.push_back(A[dq.back()]);
}
return ans;

}


#2

You should pop from forward (acc. to your implementation) before pushing the new element. You are popping from the opposite side @beast-is-live