0
How to find maximum element in 2 d vector using inbuilt function of stl ?
3 Answers
+ 1
I don't think there is a max_element function that finds the maximal element out of an arbitrarily nested vector of vectors structure.
I managed to do that transforming the inner vectors into their maximal element, collecting those in a collector vector, and then find the maximum of all maximums.
vector<int> collector;
collector.resize(a.size());
transform(
a.begin(),
a.end(),
collector.begin(),
[](vector<int>& v) {
return *max_element(v.begin(), v.end());
}
);
cout<< *max_element(collector.begin(), collector.end());
0
It takes many lines for using inbuilt function . Instead without using built in function I think is much better
0
hii