Class Solution

java.lang.Object
g1401_1500.s1402_reducing_dishes.Solution

public class Solution extends Object
1402 - Reducing Dishes.<p>Hard</p> <p>A chef has collected data on the <code>satisfaction</code> level of his <code>n</code> dishes. Chef can cook any dish in 1 unit of time.</p> <p><strong>Like-time coefficient</strong> of a dish is defined as the time taken to cook that dish including previous dishes multiplied by its satisfaction level i.e. <code>time[i] * satisfaction[i]</code>.</p> <p>Return <em>the maximum sum of <strong>like-time coefficient</strong> that the chef can obtain after dishes preparation</em>.</p> <p>Dishes can be prepared in <strong>any</strong> order and the chef can discard some dishes to get this maximum value.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> satisfaction = [-1,-8,0,5,-9]</p> <p><strong>Output:</strong> 14</p> <p><strong>Explanation:</strong> After Removing the second and last dish, the maximum total <strong>like-time coefficient</strong> will be equal to (-1*1 + 0*2 + 5*3 = 14). Each dish is prepared in one unit of time.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> satisfaction = [4,3,2]</p> <p><strong>Output:</strong> 20</p> <p><strong>Explanation:</strong> Dishes can be prepared in any order, (2*1 + 3*2 + 4*3 = 20)</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> satisfaction = [-1,-4,-5]</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> People do not like the dishes. No dish is prepared.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>n == satisfaction.length</code></li> <li><code>1 <= n <= 500</code></li> <li><code>-1000 <= satisfaction[i] <= 1000</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maxSatisfaction

      public int maxSatisfaction(int[] satisfaction)