zomvec's blog

By zomvec, history, 7 weeks ago, In English

Can anyone please tell me a solution for this problem

Given an array numbers[] of several numbers that may repeat. You are allowed to remove similar numbers in a range, the score you get after removing these numbers is let k be the number removed from the range then your score increases by k*k. You need to return the maximum score you can get after all the numbers are removed. Consider the examples for more clarity.

Examples:

Input: numbers = {1, 3, 2, 3, 2, 1, 1, 1} Output: 22 Explanation: The order in which we will follow the removals is as follows, first, we remove 2 at index (2) which adds to 1*1 because we removed just one integer, then the new array is {1, 3, 3, 2, 1, 1, 1}, now we will again remove 2 at index (3) this again adds to 1*1, the new array is {1, 3, 3, 1, 1, 1}, we now remove the range (1-2) the two 3’s, that adds up to 2*2 because we removed 2 numbers, now our array becomes {1,1,1,1} and now we remove the range (0,3) which adds up 4*4 in our sum and now our array is empty. The total sum comprises ( 1*1 + 1*1 + 2*2 + 4*4 ) = 22.

Input: numbers = {1, 1, 1, 2} Output: 10 Explanation: We at first removed 2 which is at the last index which adds up to 1*1, then our array is {1,1,1} and now we remove the entire range which adds up to 3*3 to our answer. now our answer consist of (1*1 + 3*3 ) = 10.

Full text and comments »

  • Vote: I like it
  • -8
  • Vote: I do not like it