DEV Community

Discussion on: Daily Challenge #187 - Most Sales

Collapse
 
vidit1999 profile image
Vidit Sarkar

Here is C++ solution

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;
}