This is a interview question: given an array of integers find the max. and min. using minimum comparisons.
Obviously, I can loop over the array twice and use ~
~
#include using namespace std; int main() { int n; cin>>n; set t; for(int i=0;i>x; t.insert(x); } set::iterator s,b; s=t.begin(); b=--t.end(); cout<< *s<<" "<<*b<
// this can be done in log(n) complexity!!!