DEV Community

Miss Pooja Anilkumar Patel
Miss Pooja Anilkumar Patel

Posted on

1402. Leetcode Solution in cpp

class Solution { typedef long long LL; public: int maxSatisfaction(vector<int>& A) { int N = A.size(); sort(A.begin(), A.end()); LL ans = 0; for (int i = 0; i < N; ++i) { LL sum = 0; for (int j = i; j < N; ++j) sum += A[j] * (j - i + 1); ans = max(ans, sum); } return ans; } }; 
Enter fullscreen mode Exit fullscreen mode

leetcode

challenge

here is the link for the problem:
https://leetcode.com/problems/reducing-dishes/

Top comments (0)