Please someone help me with the runtime error of this code


#include <bits/stdc++.h>
vector Solution::slidingMaximum(const vector &A, int B) {
int t;
vector max;

return max;



The size of the vector max is zero.
so u can’t access any element of the vector max. In order to access elements of the vector u should allocate memory prior to accessing the elements. So give some initialize size n to it such that t < n. so that whenever u try to access t, that particular index is present in the vector. In your case t-th element is not there since size if 0.
do something like this.
int x = int(*max_element(A.begin()+t,A.begin()+t+B));