please help me in spotting the reason for segmentation fault.
this is the link to my code:
Segmentation fault occuring
Hey @Akshita99
You need to initialisethe vector while declaring.
The line ans.push_back(ans[k-1]);
and ans[k].push_back(a[j]);
and ans[k].pop_back();
are giving errors, this is because ans[k-1] and ans[k] have garbage values. if you initialise the vector while declaring as:
vector<vector > ans(no_of_rows, vector(no_of_cols, 0));
then you won’t get segmentation error.
the segmentation fault is removed now but the values are not getting push backed into the vector. It is giving 0 only as output
i tried to pass it by reference and it again gave segmentation fault
Hey @Akshita99
initialize the vector and pass it by referrence, it won’t give segmentation fault, also, check if there is some index out of bounds error in the vector, so take the correct size of the vector
mam now there are no errors but none of the testcases is running
mam its done, i found the error
@Akshita99
That’s awesome! Also, pls mark the doubt as resolved if you don’t have any further queries.