Choose and Order Dishes for Maximum Weighted Satisfaction

Quick Overview

Choose and Order Dishes for Maximum Weighted Satisfaction. Each dish takes one unit of time. You may discard any dishes and prepare the rest in any order.

Choose and Order Dishes for Maximum Weighted Satisfaction

Company: Teradata

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

### Problem Each dish takes one unit of time. You may discard any dishes and prepare the rest in any order. If the chosen satisfaction values in cooking order are a1..am, the total is `1*a1+2*a2+...+m*am`. Return the maximum possible total, allowing no dishes. ```cpp class Solution { public: int maxSatisfaction(vector<int>& satisfaction); }; ``` ### Examples **Example 1:** ```text Input: satisfaction = [-2,3] Output: 4 Explanation: Cooking both in the listed order gives-2+6=4, more than cooking only the3. ``` **Example 2:** ```text Input: satisfaction = [0,-1,-2] Output: 0 Explanation: Cook no dishes, or only the zero-valued dish, to achieve0. ``` ### Constraints - n equals satisfaction.length and lies between 1 and 500. - `-1000 <= satisfaction[i] <= 1000`. ### Contract considerations The requested output is the optimal numeric score, not a cooking order. ```hint Read the boundary condition Account for omitted dishes, negative satisfaction, and the option to cook nothing. Cooking order affects the stated weighted score. ``` ### Boundary reminders The requested output is the optimal numeric score, not a cooking order.

Overview: Choose and Order Dishes for Maximum Weighted Satisfaction. Each dish takes one unit of time. You may discard any dishes and prepare the rest in any order.

Teradata logo
Teradata
Source window: 0–3 months · as of Oct 21, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Each dish takes one unit of time. You may discard any dishes and prepare the rest in any order. If the chosen satisfaction values in cooking order are a1..am, the total is 1*a1+2*a2+...+m*am. Return the maximum possible total, allowing no dishes.

class Solution {
public:
    int maxSatisfaction(vector<int>& satisfaction);
};

Examples

Example 1:

Input: satisfaction = [-2,3]
Output: 4
Explanation: Cooking both in the listed order gives-2+6=4, more than cooking only the3.

Example 2:

Input: satisfaction = [0,-1,-2]
Output: 0
Explanation: Cook no dishes, or only the zero-valued dish, to achieve0.

Constraints

  • n equals satisfaction.length and lies between 1 and 500.
  • -1000 <= satisfaction[i] <= 1000 .

Contract considerations

The requested output is the optimal numeric score, not a cooking order.

Boundary reminders

The requested output is the optimal numeric score, not a cooking order.