I have got Segmentation Fault.
Merge K Sorted Arrays
First resize vector to that size. Before taking input.
vector<vector<int>>v(m,vector<int>(n));
like this?
Yes, like this, else it will be of size 0.
I did that. But now Iām getting output like:
0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11
But output should be like:
0 1 2 3 4 5 6 7 8 9 10 11
Yes, that is becuase, you are using push_back(), which appends after the already resized array.
If you want to use push_back(), resize it as,
vector<vector<int>>v(m)
else, just use,
cin >> v[i][j];
1 Like