AkashCode77's blog

By AkashCode77, history, 4 months ago, In English

So last day I participated in Leetcode Biweekly Contest 124. And as stupid as I am, I misread the first problem and made it harder. Link to the first problem.

The problem statement is as follows:

Given an array of integers called nums, you can perform the following operation while nums contains at least 2 elements:

  • Choose the first two elements of nums and delete them.
  • The score of the operation is the sum of the deleted elements.

Your task is to find the maximum number of operations that can be performed, such that all operations have the same score.

Return the maximum number of operations possible that satisfy the condition mentioned above.

I thought that before we delete the elements, we could arrange nums in any order we like. Now it makes me wonder is it a known problem with the added constraint that we can arrange the array in any order to maximize the sum? Moreover, I'm unable to think of a solution with the added constraint. I want to know the optimal way of solving this problem with the added constraint.


Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it