Easy short o(n) sol. cpp


#1
int Solution::maxp3(vector<int> &A) {
    auto m=max_element(A.begin(),A.end());
    int m1=(*m);
    A.erase(m);
    m=min_element(A.begin(),A.end());
    int n1=(*m);
    A.erase(m);
    if(A.size()==1) return m1*n1*A[0];
    else{
        m=max_element(A.begin(),A.end());
        int m2=(*m);
        A.erase(m);    
        return max((m1*n1*(*min_element(A.begin(),A.end()))),(m1*m2*(*max_element(A.begin(),A.end()))));}
}