Company: Teradata

Difficulty: medium

Problem Statement

Maximum Like-Time Coefficient You are given the satisfaction values of `n` dishes. Cooking each selected dish takes one unit of time. If a dish with satisfaction `s` is cooked in position `t` (positions start at 1), it contributes `t * s` to the like-time coefficient. You may discard any dishes and may cook the remaining dishes in any order. Print the maximum possible total like-time coefficient. Input The first line contains an integer `n`. The second line contains `n` integers, the satisfaction values. Output Print the maximum possible like-time coefficient. Constraints - `1 <= n <= 500` - `-1000 <= satisfaction[i] <= 1000` Example Input: `5` followed by `-1 -8 0 5 -9` Output: `14` Cook `-1, 0, 5` in that order: `1 * -1 + 2 * 0 + 3 * 5 = 14`. Notes The empty selection is allowed, so the answer is never negative.

More Teradata OA questionsInterview experiences