vector<string> highestRevenue(vector<string> products, vector<int> amounts, vector<int> prices){
vector<int> revenue; // holds the revenue of all products
for(int i=0; i<amounts.size();i++){
revenue.push_back(amounts[i]*prices[i]);
}
int max_revenue = *max_element(revenue.begin(),revenue.end()); // maximum revenue
if(max_revenue == 0)
return vector<string>(); // if maximum revenue is zero then there is no need to return any product
vector<string> highestRevProducts; // vector storing the products with maximum revenue
for(int i=0;i<revenue.size();i++)
if(revenue[i] == max_revenue)
highestRevProducts.push_back(products[i]);
return highestRevProducts;
}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here is C++ solution