How to find maximum element in 2 d vector using inbuilt function of stl ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to find maximum element in 2 d vector using inbuilt function of stl ?

https://code.sololearn.com/cmy8ldBmX7up/?ref=app

26th Jan 2022, 1:36 PM
Srishti Jaiswal
Srishti Jaiswal - avatar
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());
26th Jan 2022, 3:23 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar
0
It takes many lines for using inbuilt function . Instead without using built in function I think is much better
26th Jan 2022, 5:47 PM
Srishti Jaiswal
Srishti Jaiswal - avatar
0
hii
27th Jan 2022, 4:58 PM
Deepak Mastkar